Recent Posts

This Post Has Been Viewed 1,829 Times.

Simple PHP mail Script

Posted by admin | Posted in PHP, scripts | Posted on 28-02-2009

1

Simple PHP mail scriptThe script will simply send a mail to the e-mail id you provide in the coresponding field i have given, just check this out..

  1. <html>
  2. <head><title>Mail sender</title></head>
  3. <body>
  4. <form action=”mail.php” method=”POST”>
  5. <b>Email</b><br>
  6. <input type=”text” name=”email” size=40>
  7. <p><b>Subject</b><br>
  8. <input type=”text” name=”subject” size=40>
  9. <p><b>Message</b><br>
  10. <textarea cols=40 rows=10 name=”message”></textarea>
  11. <p><input type=”submit” value=” Send “>
  12. </form>
  13. </body>
  14. </html>

The form contains the necessary text fields Email, Subject, Message, and the Send button. The line<form action=”mail.php” method=”POST”>tells the browser which PHP file will process the form and what method to use for sending data.When the user fills in the form and hits the Send button, the mail.php file is called…

  1. <html>
  2. <head><title>PHP Mail Sender</title></head>
  3. <body>
  4. <?php
  5. /* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */
  6. $email = $HTTP_POST_VARS['email'];
  7. $subject = $HTTP_POST_VARS['subject'];
  8. $message = $HTTP_POST_VARS['message'];
  9. /*Validation of subject and also mail */
  10. if (!preg_match(”/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/”, $email)) {
  11.   echo “<h4>Invalid email address</h4>”;
  12.   echo “<a href=’javascript:history.back(1);’>Back</a>”;
  13. } elseif ($subject == “”) {
  14.   echo “<h4>No subject</h4>”;
  15.   echo “<a href=’javascript:history.back(1);’>Back</a>”;
  16. }
  17. /* Sends the mail and outputs the “Thank you” string if the mail is successfully sent, or the error string 
  18. otherwise. */
  19. elseif (mail($email,$subject,$message)) {
  20.   echo “<h4>Thank you for sending email</h4>”;
  21. } else {
  22.   echo “<h4>Can’t send email to $email</h4>”;
  23. }
  24. ?>
  25. </body>
  26. </html>
VN:F [1.5.7_846]
Rating: 10.0/10 (1 vote cast)
VN:F [1.5.7_846]
Rating: 0 (from 0 votes)
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • De.lirio.us
  • Xerpi

Related posts:

  1. HTML E-mail Using PHP
  2. PHP E-mail with attachment
  3. Pass PHP Value To Javascript
  4. Simple file upload script using php
  5. Simple PHP Login Script
  6. Load Another Webpage Content Using Simple Jquery
  7. Words Validation with Javascript

Comments (1)

good script..

VA:F [1.5.7_846]
Rating: 0.0/5 (0 votes cast)
VA:F [1.5.7_846]
Rating: 0 (from 0 votes)

Write a comment

Spam Protected