Advertisement
Guest User

Untitled

a guest
May 25th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. <html>
  2. <head><title>PHP Mail Sender</title></head>
  3. <body>
  4. <?php
  5.  
  6. /* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */
  7. $email = $HTTP_POST_VARS['email'];
  8. $subject = $HTTP_POST_VARS['subject'];
  9. $message = $HTTP_POST_VARS['message'];
  10.  
  11. /* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */
  12. if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
  13. echo "<h4>Invalid email address</h4>";
  14. echo "<a href='javascript:history.back(1);'>Back</a>";
  15. } elseif ($subject == "") {
  16. echo "<h4>No subject</h4>";
  17. echo "<a href='javascript:history.back(1);'>Back</a>";
  18. }
  19.  
  20. /* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */
  21. elseif (mail($email,$subject,$message)) {
  22. echo "<h4>Thank you for sending email</h4>";
  23. } else {
  24. echo "<h4>Can't send email to $email</h4>";
  25. }
  26. ?>
  27. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement