PHP Mail Part 2


Well, im back, I already coded the first bit of PHP Mail, so go check it out before reading this.

This time, ill make a code that will automatically form a email so you don't have to write it out each and every time! Lets get started:

sendo.html:
PHP Code
  1. <form action="sendo.php" method="post">
  2. To: <input type="text" name="email"><BR> <!-- Put email of user there -->
  3. From: <input type="text" name="emailfrom"><BR> <!-- Put email of you, or your name. -->
  4. Subject: <input type="text" name="subject"> <!-- Put the subject here --><BR>
  5. Message:<BR><textarea name="message">Put your message here</textarea><BR>
  6. <input type="submit" value="Submit">
  7. </form>


Easy enough right? Sure? Now for the PHP which will send it!

sendo.php:
PHP Code
  1. <?php
  2. $to = $_POST['email'];
  3. $from = $_POST['emailfrom'];
  4. $subject = $_POST['subject'];
  5. $message = $_POST['message'];
  6. $mess = "You have received a message from YOURSITEHERE. The subject line was: $subject. \r
  7. $message \r
  8. The message was sent from the email/name of: $from.";
  9.  
  10. if ( (!$to)||(!$subject)||(!$message) ) {
  11. echo "Please fix the following:<BR>";
  12. if(!$to) {
  13. echo "Please enter the email to who you are sending the message to<BR>"; }
  14. if(!$subject) {
  15. echo "Please fill in a subject!<BR>"; }
  16. if(!$message) {
  17. echo "What are you planning to send?<BR><BR>"; }
  18. echo "<form action='ie.php' method='post'>
  19. To: <input type='text' name='email'><BR> <!-- Put email of user there -->
  20. From: <input type='text' name='emailfrom'><BR> <!-- Put email of you, or your name. -->
  21. Subject: <input type='text' name='subject'> <!-- Put the subject here --><BR>
  22. Message:<BR><textarea name='message'>Put your message here</textarea><BR>
  23. <input type='submit' value='Submit'>
  24. </form>";
  25. } else {
  26. mail("$to", "Subject: $subject", $mess, "From: $from");
  27.  
  28. if(mail) {
  29. echo "Your message was sent";
  30. } else {
  31. echo "Sorry, there was a error sending the message";
  32. }
  33. }
  34. ?>


**Note: I noticed if your using a spam controll (Spam Assassin), the message will not go threw, but it works with Gmail, hotmail, and any Hosting without Spam Assassin.

Another Easy Tutorial, end of the series. Hope you like.
Diablosblizz's Avatar
Views:
2,346
Rating:
There are currently no comments for this tutorial, login or register to leave one.