Skip to main content

How To Create A Contact Form | P.3

Posted on August 24, 2011 by Jaffe WorleyJaffe Worley

This screencast will finish up showing you how to create the PHP form in our contact form. The php will show you how to send mail using the mail() function as well as sending the proper headers.

Download Source

Creating A Contact Form P4 – JavaScript OnBlur
How To Create A Contact Form | P.2
How To Create A Contact Form | P.1


Image of Hampus
9 years ago

I really like your tutorials, you explain very detailed.
But this Form doesn’t seem to work for me, I get this when i press send:
“; echo $error. ”
“; echo “Please go back and fix these errors.
“; die(); } // validation if(!isset($_POST[‘name’]) || !isset($_POST[’email’]) || !isset($_POST[‘comments’])){ died(‘We are sorry but there appears to be a problem with the form you submitted.’); } $name = $_POST[‘name’]; $email = $_POST[’email’]; $comments = $_POST[‘comments’]; $error_message = “”; $email_exp = ‘/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z] {2,4}$/’; if(!preg_match($email_exp, $email)){ $error_message .= ‘The Email address you entered does not appear to be valid.
‘; } $string_exp = “/^[A-Za-z.’-]+$/”; if (!preg_match($string_exp, $name)){ $error_message .= ‘The Name you entered does not appear to be valid.
‘; } if(strlen($comments) 0 ){ died($error_message); } $email_message = “Form Details below.nn”; function clean_string($string){ $bad = array(“content-type”, “bcc:”, “to:”, “cc:”, “href”); return str_replace($bad, “”, $string); } $email_message .= “Name:” . clean_string($name) . “n”; $email_message .= “Email:” . clean_string($email) . “n”; $email_message .= “Comments:” . clean_string($comments) . “n”; // create email headers $headers = ‘From: ‘ .$email_From . “rn”. ‘Reply-To:’ .$email. “rn” . ‘X-Mailer: PHP/’ . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> Thank you for contacting us. We will be in touch with you shortly.
Please click here to go back to the form.
So I’m obviously new to php and I dont know what to do ^^

Leave a Reply

Your email address will not be published. Required fields are marked *