Posted By

Tamedo on 01/27/08


Tagged


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

ejosullivan
SmpleJohn
lee
jprice
Mench59


php contact form


 / Published in: PHP
 

  1. <?php
  2. // declare values
  3. $contact_email = $_POST['EmailAddress'];
  4. $contact_subject = $_POST['Subject'];
  5. $contact_name = $_POST['FullName'];
  6. $contact_message = $_POST['Message'];
  7. $mydate = date ( 'l, F d Y g:i A',time()+240 );
  8.  
  9. // where to send e-mail to
  10. $to = '[email protected]';
  11.  
  12. // e-mail subject
  13. $subject = "Message submitted using Contact Us form";
  14.  
  15. // e-mail message
  16. $message = "You have received a contact message:
  17. "
  18.  
  19. ."----------------------------------------------------------------
  20. "
  21. ."Contact Name: $contact_name
  22. "
  23. ."Subject: $contact_subject
  24. "
  25. ."Submitted: $mydate
  26. "
  27. ."From IP: {$_SERVER['REMOTE_ADDR']}
  28.  
  29. "
  30. ."Message: $contact_message
  31. "
  32. ."Form Address: {$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}";
  33.  
  34. $headers = "From: $contact_name <$contact_email>\n"
  35. ."Reply-To: $contact_email\n"
  36. ."X-Mailer: PHP/".phpversion();
  37.  
  38. // check for validation, then send the e-mail
  39. if(empty($contact_name) || empty($contact_email) || empty($contact_subject) || empty($contact_message)) {
  40. echo '<p>Send us a message, enter your information below and click \'Submit\'!</p>
  41. <form method="post" action="">
  42. <table id="Form-Details">
  43. <tbody>
  44. <tr><td>Name:</td><td><input type="text" name="FullName" size="20" /></td>
  45. <td>Subject:</td><td><input type="text" name="Subject" size="20" /></td></tr>
  46. <tr><td>Email:</td><td colspan="3"><input type="text" name="EmailAddress" size="20" /></td></tr>
  47. <tr><td colspan="4">Message:</td></tr>
  48. <tr><td colspan="4"><textarea rows="6" name="Message" cols="47" class="input"></textarea></td></tr>
  49. <tr><td colspan="4" class="right1"><input type="submit" value="Submit" /><input type="reset" value="Reset" /></td></tr>
  50. </tbody>
  51. </table>
  52. </form>';
  53. } elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $contact_email)) {
  54. echo "<p>ERROR: Please enter a valid e-mail address.</p>";
  55. } else {
  56. mail( $to, $subject, $message, $headers );
  57. echo "<h3>Message Sent!</h3><p>Dear $contact_name,<br /><br />We will get back to you as soon as possible using $contact_email.";
  58. }
  59. ?>

Report this snippet  

You need to login to post a comment.