Posted By

ryarwood on 07/07/10


Tagged

form php process


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

joacoleo
rlynch3


Basic PHP Form


 / Published in: PHP
 

Basic mail form.

  1. <?php
  2. # | $Id$
  3.  
  4. define('SITE_BASE', dirname(__FILE__));
  5. require_once SITE_BASE . '/mime.php';
  6.  
  7. $mail = array();
  8.  
  9. # | email headers
  10. # | NEED TO EDIT THIS SECTION
  11. $mail['sender'] = $_POST['eMail'];
  12. $mail['recipient'] = '[email protected]';
  13. $mail['subject'] = 'Interactive Marketing Tools';
  14. $mail['header'] = sprintf("From: %s\n", $mail['sender']);
  15. $mail['header'] .= sprintf("Reply-To: %s",$mail['sender']);
  16.  
  17. # | email field content
  18. # | AND EDIT THIS BELOW
  19. $mail['fields'][] = array('label' => 'First Name', 'variable' => $_POST['firstName']);
  20. $mail['fields'][] = array('label' => 'Last Name', 'variable' => $_POST['lastName']);
  21. $mail['fields'][] = array('label' => 'company', 'variable' => $_POST['company']);
  22. $mail['fields'][] = array('label' => 'address', 'variable' => $_POST['address']);
  23. $mail['fields'][] = array('label' => 'city', 'variable' => $_POST['city']);
  24. $mail['fields'][] = array('label' => 'state', 'variable' => $_POST['state']);
  25. $mail['fields'][] = array('label' => 'zip', 'variable' => $_POST['zip']);
  26. $mail['fields'][] = array('label' => 'phone', 'variable' => $_POST['phone']);
  27. $mail['fields'][] = array('label' => 'fax', 'variable' => $_POST['fax']);
  28. $mail['fields'][] = array('label' => 'eMail', 'variable' => $_POST['eMail']);
  29. $mail['fields'][] = array('label' => 'webURL', 'variable' => $_POST['webURL']);
  30. $mail['fields'][] = array('label' => 'howDid', 'variable' => $_POST['howDid']);
  31. $mail['fields'][] = array('label' => 'comments', 'variable' => $_POST['comments']);
  32.  
  33. # | message formatting
  34. # | NO NEED TO TOUCH BELOW HERE
  35. $mail['message'] = "_____________________________________\n";
  36.  
  37. foreach($mail['fields'] as $field) {
  38. $mail['message'] .= sprintf("%s: %s\n",$field['label'], stripslashes($field['variable']));
  39. }
  40.  
  41. $mail['message'] .= "_____________________________________\n";
  42.  
  43. # | mail dispatch
  44. mail( $mail['recipient'], $mail['subject'], $mail['message'], $mail['header']);
  45.  
  46. ?>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Masis on July 8, 2010

According to php form tutorial when dealing with HTML forms and PHP it is necessary to remember that any form element in HTML page will automatically be available to the PHP scripts. I.E:

    Name *



      Email *



      Phone



      Field_check

         Check_1
         Check_2
         Check_3



      Message *

You need to login to post a comment.