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.
<?
//Go to http://www.dells.com/mail/example/send_mail.htm to see
//this code in action. The source code and documentation
//will be E-mailed to you.
//
//This code snipet will open and read the contents of
//a text file into a string variable called $body.
//It then formats headers and sends out an E-mail
//message using the built-in mail() function in PHP3.
//
//The body of the E-mail message will be identical
//to the contents of a text file you create. As this
//snipet is written, the text file must be located in
//the same directory as the mail.php3 script. It must be
//strictly ASCII text without control codes of any kind.
//However, with a little bit of experimentation, you
//should be able to send out HTML mail as well. I have not
//tested that however.
//
//On Windows, make the txt file with Notepad and turn off
//Word Wrap. On UNIX/BSD use Pica to make the txt file.
//
//The PHP3 mail() function will send the E-mail to the
//contents of variable $email. This script is expecting
//this variable to be passed from an HTML form that has
//a text input named "email" on it. The HTML forms method
//is "post" and use the path and file name of this script
//as the "action" attribute.
//
//Of course, you can always wrap this code in a function
//and use it anyplace in your own code to send E-mail in
//the background.
$textfile = "send_mail.txt"; //This is the name of the txt file you wrote
$mailsubject = "Sending E-Mail via PHP3";
$mailheaders = "From: studioq@chorus.net\n";
$mailheaders .= "Cc: \n";
$mailheaders .= "Bcc: studioq@chorus.net\n";
$mailheaders .= "Reply-To: studioq@chorus.net\n";
$mailheaders .= "X-Mailer: PHP3 Mail Function on Apache/BSD\n";
$mailheaders .= "X-Anything: isn't this cool?";
$msg = "Thank you $fname $lname for requesting this script!\n";
$msg .= "We hope it meets your needs.\n";
//open the txt file and assign the file handle
//to variable $fhandle
//then read the text file into variable $msg
//and close the txt file
//IMPORTANT: be certain that you close any file you
//open or you will cause massive memory use!
if($fhandle = fopen($textfile, "r")) {
$body = fread($fhandle,filesize($textfile));
fclose($fhandle); //CLOSE THE FILE
} else {
print("Error: the txt file could not be opened or read.");
}
//Send the mail
$msg .= $body;
if (mail($email, $mailsubject, $msg, $mailheaders)) {
print("You will receive an E-mail message from studioq@chorus.net<BR>\n");
print("Please let us know if you used this script and if it meets your needs.\n");