HTML
First of all create 2 files: contact_form.html and contact.php. The first file will contain HTML code for the form and the second -will process the data from the form
And this is how it will look in the browser
<formaction="contact.php"method="post">Your name<inputtype="text"name="cf_name">Your e-mail<inputtype="text"name="cf_email">Message<textareaname="cf_message"><inputtype="submit"value="Send"><inputtype="reset"value="Clear"></form>
PHP
Let’s have a quick look at some main aspects of it. The
$mail_to shall contain the site owner email, this is where the email is sent to. You can specify multiple emails by separating them with a comma (e.g. mail-one@template-help.com, mail-two@template-help.com)
Subject of the email you receive from the contact form$mail_to='test@test-mail.com';
Constructing the body of the message$subject='Message from a site visitor '.$field_name;
Constructing the headers of the message$body_message='From: '.$field_name."\n";$body_message.='E-mail: '.$field_email."\n";$body_message.='Message: '.$field_message;
Defining mail() function and assigning it to a variable $mail_status, which is used below to check whether the mail has been sent or not$headers="From: $cf_email\r\n";$headers.="Reply-To: $cf_email\r\n";
If the mail() function executed successfully then do the code below$mail_status= mail($mail_to,$subject,$body_message,$headers);
If the mail() function fails, then execute the following codeif($mail_status) { ?><script language="javascript"type="text/javascript">// Print a messagealert('Thank you for the message. We will contact you shortly.');// Redirect to some page of the site. You can also specify full URL, e.g. http://template-help.comwindow.location ='contact_page.html';</script><?php}
else{ ?><script language="javascript"type="text/javascript">// Print a messagealert('Message failed. Please, send an email to gordon@template-help.com');// Redirect to some page of the site. You can also specify full URL, e.g. http://template-help.comwindow.location ='contact_page.html';</script><?php}?>
You can also download compiled contact_form.html and contact.php files in a single package
Proceed to the tutorial on how to add fields to the contact form




