Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2013
219
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///// content of newsletter.php
  2. <?php
  3. //If the form is submitted
  4. if(isset($_POST['submit'])) {
  5.  
  6. //Check to make sure sure that a valid email address is submitted
  7. if(trim($_POST['email']) == '') {
  8. $hasError = true;
  9. } else if (!preg_match("/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$/", trim($_POST['email']))) {
  10. $hasError = true;
  11. } else {
  12. $email = trim($_POST['email']);
  13. }
  14.  
  15. //If there is no error, send the email
  16. if(!isset($hasError)) {
  17. $emailTo = 'test@test.com'; //Put your own email address here
  18. $subject = "Newsletter subscription";
  19. $body = "Email: $email";
  20. $headers = "From: $email";
  21.  
  22. mail($emailTo, $subject, $body, $headers);
  23. }
  24.  
  25. die("<span class='success'>Success! Your message has been sent.</span>");
  26. }
  27. ?>
  28.  
  29.  
  30. /// content of mail.php
  31. <?php
  32. //If the form is submitted
  33. if(isset($_POST['submit'])) {
  34.  
  35. //Check to make sure that the name field is not empty
  36. if(trim($_POST['contactname']) == '') {
  37. $hasError = true;
  38. } else {
  39. $name = trim($_POST['contactname']);
  40. }
  41.  
  42. //Check to make sure that the subject field is not empty
  43. if(trim($_POST['subject']) == '') {
  44. $hasError = true;
  45. } else {
  46. $subject = trim($_POST['subject']);
  47. }
  48.  
  49. //Check to make sure sure that a valid email address is submitted
  50. if(trim($_POST['email']) == '') {
  51. $hasError = true;
  52. } else if (!preg_match("/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$/", trim($_POST['email']))) {
  53. $hasError = true;
  54. } else {
  55. $email = trim($_POST['email']);
  56. }
  57.  
  58. //Check to make sure comments were entered
  59. if(trim($_POST['message']) == '') {
  60. $hasError = true;
  61. } else {
  62. if(function_exists('stripslashes')) {
  63. $comments = stripslashes(trim($_POST['message']));
  64. } else {
  65. $comments = trim($_POST['message']);
  66. }
  67. }
  68.  
  69. //If there is no error, send the email
  70. if(!isset($hasError)) {
  71. $emailTo = 'test@test.com'; //Put your own email address here
  72. $body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
  73. $headers = "From: $email";
  74.  
  75. mail($emailTo, $subject, $body, $headers);
  76. }
  77.  
  78. die("<span class='success'>Success! Your message has been sent.</span>");
  79. }
  80. ?>
Advertisement
RAW Paste Data Copied
Advertisement