HTML Email Form $_POST Contents


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

I use this to activate basic forms for clients. Just make sure your form input names are named appropriately. Any inputs such as phone or fax that are separated into different inputs should have the same name.


Copy this code and paste it in your HTML
  1. $headers = "Content-Type: text/html; charset=iso-8859-1\n";
  2. $subject = "New Form Submission";
  3.  
  4. // set html email content
  5. $text = "<html><body>The form details are listed below:<br><br><table>";
  6.  
  7. // loop through POST
  8. foreach($_POST as $key => $value)
  9. {
  10. if(is_array($value)){
  11. if(strstr($key, "phone") || strstr($key,"fax")){
  12. $value = implode("-",$value);
  13. }else{
  14. $value = implode(",",$value);
  15. }
  16. }
  17. $text .= "<tr><td>".$key."</td><td>".$value."</td></tr>";
  18. }
  19.  
  20. $text .= "</table></body></html>";
  21.  
  22. // you may need to add some form inputs manually depending on your setup
  23.  
  24. //email admin to notify of new submission
  25. mail($to, $subject, $text, $headers);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.