First we want to start with the opening PHP tag and then add the subject variable and the mailto variable. This will add the subject to the email and tell the script where to send the email.
<?php $emailSubject = 'Customer Has a Question!'; $webMaster = 'you@yourdomain.com';
Next we want to let the server know what information to get from the form. You need to make sure that the names of the fields are the same as what you put here, otherwise it will not gather the information properly.
$nameField = $_POST ['name']; $emailField = $_POST['email']; $questionField = $_POST ['question'];
The “<<<EOD” lets the server know that everything between that tag goes in the email body. However you arrange it here, it will show up the same way in the email.
$body = <<<EOD <br><hr><br> Name: $name <br> Email: $email <br> Questions: $question <br> EOD; $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n";
The first $header tag enables the person’s email address to show up properly. “\r\n” is a line break that lets the server know that the line has ended. The other $header tag lets the server know that this is both text and HTML; if this is not there then all the <br> tags and other coding will show up in the email.
The following code lets the server know that if everything is successful, send all the previous variables to the email client
$success = mail($webMaster, $emailSubject, $body, $headers);
Between the following EOD tags you would want to put you confirmation page.
$theResults = <<<EOD
EOD;
The following code allows what is written between the opening and closing EOD statements to be seen on the page. Lastly you want to put the closing PHP tag in and close the script.
echo “$theResults”;
?>