Advertisement
firoze

Basic PHP mail() Function code to send emails from a form

Nov 14th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. // Basic PHP mail() Function code to send emails from a form
  2.  
  3. <?php
  4. //if "email" variable is filled out, send email
  5. if (isset($_REQUEST['email'])) {
  6.  
  7. //Email information
  8. $admin_email = "[email protected]";
  9. $email = $_REQUEST['email'];
  10. $subject = $_REQUEST['subject'];
  11. $comment = $_REQUEST['comment'];
  12.  
  13. //send email
  14. mail($admin_email, "$subject", $comment, "From:" . $email);
  15.  
  16. //Email response
  17. echo "Thank you for contacting us!";
  18. }
  19.  
  20. //if "email" variable is not filled out, display the form
  21. else {
  22. ?>
  23.  
  24. <form method="post">
  25. Email: <input name="email" type="text" /><br />
  26. Subject: <input name="subject" type="text" /><br />
  27. Message:<br />
  28. <textarea name="comment" rows="15" cols="40"></textarea><br />
  29. <input type="submit" value="Submit" />
  30. </form>
  31.  
  32. <?php
  33. }
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement