Posted By

sandman7OR on 08/08/10


Tagged

forms


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Mench59


Basic Form Handler


 / Published in: PHP
 

processes contact form input and produces an auto reply

  1. <?php
  2.  
  3. $fields = array();
  4. $fields{"Name"} = "Name";
  5. $fields{"Email"} = "Email";
  6. $fields{"Message"} = "Message";
  7.  
  8. $to = "[email protected]" ;
  9. $from = $_REQUEST['Email'] ;
  10. $name = $_REQUEST['Name'] ;
  11. $headers = "From: $from";
  12. $subject = "NCCDC Web contact -- From contact page";
  13.  
  14. $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]); }
  15.  
  16. /*Second email */
  17. $headers2 = "From: [email protected]";
  18. $subject2 = "Thank you for contacting NCCDC";
  19. $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";
  20. $autoreply .= "\n\n You Wrote: \n".$_REQUEST["Message"];
  21.  
  22. if($from == '') {print "You have not entered an email, please go back and try again";}
  23. else {
  24. if($name == '') {print "You have not entered a name, please go back and try again";}
  25. else {
  26. $send = mail($to, $subject, $body, $headers);
  27. $send2 = mail($from, $subject2, $autoreply, $headers2);
  28. if($send)
  29. {header( "Location: ../thankyou/" );}
  30. else
  31. {print "We encountered an error sending your mail, please notify [email protected]"; }
  32. }
  33. }
  34. ?>

Report this snippet  

You need to login to post a comment.