PHP Mail


Its easy, and doesn't require and MYSQL databases. Well, lets get started.

First off, the form.

sendf.html:
PHP Code
  1. <form action='sende.php' method='post'>
  2. Your name: <input type='text' name='name'><BR>
  3. Subject: <input type='text' name='subject'><BR>
  4. Email: <input type='text' name='email'><BR>
  5. Message:<BR>
  6. <textarea name='message'>Put your message here</textarea><BR>
  7. <input type='submit' value='Submit'>
  8. </form>


You can change the sizes of your boxes, thats up to you. Pritty much the above code just puts a form on your page, then once you click submit it sends it to your email which you can specify below.

sende.php:
PHP Code
  1. <?php
  2. $name = $_POST['name']; // gets the users name
  3. $subject = $_POST['subject']; //gets the subject
  4. $message = $_POST['message']; // gets the message
  5. $email = $_POST['email']; // gets the users email
  6. $mail = "
  7. Dear, Owner. You have a message from your site ($name). The subject line is: $subject. Below is the message: \r
  8. $message \r
  9. The message is from the email address of: $email."; // you can change this to whatever you want
  10.  
  11. if ( (!$subject)||(!$message) ) { // checks for the missing
  12. echo "Please fix the following:<BR>";
  13. if(!$subject) {
  14. echo "Please fill in your subject<BR>"; // checks for subject
  15. }
  16. if(!$message) {
  17. echo "Please fill in the message<BR><BR>"; // checks for message
  18. }
  19. echo "<form action='sende.php' method='post'>
  20. Your name: <input type='text' name='name'><BR>
  21. Subject: <input type='text' name='subject'><BR>
  22. Email: <input type='text' name='email'><BR>
  23. Message:<BR>
  24. <textarea name='message'>Put your message here</textarea><BR>
  25. <input type='submit' value='Submit'>
  26. </form>";
  27. } else {
  28.  
  29. mail("EMAILHERE@DOMAINHERE.com", "Subject: $subject", $mail, "From: $name <$email>");
  30.  
  31. if(mail) {
  32. echo "Thank you please wait for a reply";
  33. } else {
  34. echo "Error: Message could not be sent";
  35. }
  36. }
  37. // hope this helps
  38. ?>


I tested the code above and it works. I hope this helps you a lot.

Enjoy.

COMMING SOON: A WAY TO EMAIL YOUR USERS FROM A FORM :O.
Diablosblizz's Avatar
Views:
2,385
Rating:
Posted on Sunday 6th May 2007 at 04:56 PM
Diablosblizz
Diablosblizz's Avatar
Don't understand?
Posted on Sunday 6th May 2007 at 01:28 PM
cyruswu
cyruswu's Avatar
I wish there was once to view the email.