home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / mail.php3.txt < prev    next >
Encoding:
Text File  |  2002-05-06  |  2.9 KB  |  82 lines

  1. mail.php3 
  2.  
  3. Send E-mail automatically from your site using the built-in mail() function of PHP3. The body of the e-mail will be taken from a text file that you create. Easily modified. Source code will be mailed to you. 
  4.  
  5.  
  6.  
  7. <?
  8. //Go to http://www.dells.com/mail/example/send_mail.htm to see 
  9. //this code in action. The source code and documentation
  10. //will be E-mailed to you.
  11. //
  12. //This code snipet will open and read the contents of
  13. //a text file into a string variable called $body.
  14. //It then formats headers and sends out an E-mail
  15. //message using the built-in mail() function in PHP3.
  16. //
  17. //The body of the E-mail message will be identical
  18. //to the contents of a text file you create. As this
  19. //snipet is written, the text file must be located in
  20. //the same directory as the mail.php3 script. It must be
  21. //strictly ASCII text without control codes of any kind.
  22. //However, with a little bit of experimentation, you
  23. //should be able to send out HTML mail as well. I have not
  24. //tested that however.
  25. //
  26. //On Windows, make the txt file with Notepad and turn off
  27. //Word Wrap. On UNIX/BSD use Pica to make the txt file.
  28. //
  29. //The PHP3 mail() function will send the E-mail to the
  30. //contents of variable $email. This script is expecting
  31. //this variable to be passed from an HTML form that has
  32. //a text input named "email" on it. The HTML forms method
  33. //is "post" and use the path and file name of this script
  34. //as the "action" attribute.
  35. //
  36. //Of course, you can always wrap this code in a function
  37. //and use it anyplace in your own code to send E-mail in 
  38. //the background.
  39.  
  40.  
  41. $textfile = "send_mail.txt"; //This is the name of the txt file you wrote
  42. $mailsubject = "Sending E-Mail via PHP3";
  43. $mailheaders = "From: studioq@chorus.net\n";
  44. $mailheaders .= "Cc: \n";
  45. $mailheaders .= "Bcc: studioq@chorus.net\n";
  46. $mailheaders .= "Reply-To: studioq@chorus.net\n";
  47. $mailheaders .= "X-Mailer: PHP3 Mail Function on Apache/BSD\n";
  48. $mailheaders .= "X-Anything: isn't this cool?";
  49.  
  50. $msg = "Thank you $fname $lname for requesting this script!\n";
  51. $msg .= "We hope it meets your needs.\n";
  52.  
  53.     //open the txt file and assign the file handle
  54.     //to variable $fhandle
  55.     //then read the text file into variable $msg
  56.     //and close the txt file
  57.     //IMPORTANT: be certain that you close any file you
  58.     //open or you will cause massive memory use!
  59.  
  60.    if($fhandle = fopen($textfile, "r")) {
  61.     $body = fread($fhandle,filesize($textfile));
  62.            fclose($fhandle);  //CLOSE THE FILE
  63.       } else {
  64.     print("Error: the txt file could not be opened or read.");
  65.     }
  66.  
  67.  
  68. //Send the mail
  69.  
  70. $msg .= $body;
  71.  
  72.     if (mail($email, $mailsubject, $msg, $mailheaders)) {
  73.  
  74.         print("You will receive an E-mail message from studioq@chorus.net<BR>\n");
  75.         print("Please let us know if you used this script and if it meets your needs.\n");
  76.     }
  77.      else {
  78.         print("Error: The message could not be sent.\n");
  79.     }
  80.  
  81. ?>
  82.