Basic Form Handler


/ Published in: PHP
Save to your folder(s)

processes contact form input and produces an auto reply


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. $fields = array();
  4. $fields{"Name"} = "Name";
  5. $fields{"Email"} = "Email";
  6. $fields{"Message"} = "Message";
  7.  
  8. $from = $_REQUEST['Email'] ;
  9. $name = $_REQUEST['Name'] ;
  10. $headers = "From: $from";
  11. $subject = "NCCDC Web contact -- From contact page";
  12.  
  13. $body = "WEB CONTACT FROM NCCDC \n\n We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
  14.  
  15. /*Second email */
  16. $headers2 = "From: [email protected]";
  17. $subject2 = "Thank you for contacting NCCDC";
  18. $autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usually within 48 hours. If you have any more questions, please consult our website at www.pdxchild.org";
  19. $autoreply .= "\n\n You Wrote: \n".$_REQUEST["Message"];
  20.  
  21. if($from == '') {print "You have not entered an email, please go back and try again";}
  22. else {
  23. if($name == '') {print "You have not entered a name, please go back and try again";}
  24. else {
  25. $send = mail($to, $subject, $body, $headers);
  26. $send2 = mail($from, $subject2, $autoreply, $headers2);
  27. if($send)
  28. {header( "Location: ../thankyou/" );}
  29. else
  30. {print "We encountered an error sending your mail, please notify [email protected]"; }
  31. }
  32. }
  33. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.