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

Report this snippet  

You need to login to post a comment.