|
|
|
| Title : |
PHP3 FormMail This script sends E-mail using PHP3 function mail(). Body of
message is from text file that you create. Easily modified. |
| Categories : |
PHP, Email, IMAP |
 Steven Killick |
| Date : |
Sep 03rd 1999 |
| Grade : |
2 of 5 (graded 2 times) |
| Viewed : |
10080 |
| File : |
No file for this code example. |
| Images : |
No Images for this code example. |
|
| Search : |
More code by Steven Killick |
|
| Action : |
Grade This Code Example
|
|
| Tools : |
My Examples List |
|
|
|
|
|
|
NOTE: This script will function only if the version of php3 on your server has been compiled
with the latest CVS for fread(). If you receive a fatal error saying that there was a call to an
unsupported function, fread(), you will have to contact your hosting company and ask them to
re-compile PHP3 with the lastest CVS for fread().
Copy and paste everything between <? and ?> (below) into a new file. Name it mail.php3 and
make the changes in the script to accomplish your goal and save them. Then create a text file
that contains the message you want to send. Save it under whatever name you want and in
the same directory as the mail.php3 script. Be sure to change the value of the variable
$textfile to the name of the text file you wrote and saved.
The script is expecting to receive a value for the variable $email. I used a text field named
'email' on the HTML form you filled out when you asked for this script, to pass your e-mail
address to this variable. Of course, you can fill this variable anyway you choose. To see a
working example, go to http://www.chatpic.com/library/php3/mail/send_mail.htm
<?
//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: \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?";
//Begin the message. Variables $fname and $lname are passed from
//the HTML form you used to request this script.
$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 $body
//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.");
}
//add the contents of your text file ($body) to the variable $msg
$msg .= $body;
//Send the mail
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");
}
else {
print("Error: The message could not be sent.\n");
}
?>
***********************************
Studio Q Development
*********************************** |
|
| A PHP based webmail at : http://www.horde.org/imp Categories : Email, IMAP, PHP, Complete Programs | | | imap_sort Categories : IMAP, Email, PHP, PHP Functions | | | imap_subscribe -- Subscribe to a mailbox Categories : PHP, PHP Functions, IMAP, Email | | | Email a user with out exposing email address Categories : PHP, Databases, MySQL, Email | | | Class for sending mail with MIME attachments in multipart format using external sendmail, mimencode and zip Categories : Email, Network, PHP, PHP Classes | | | Broadcast HTML Email Categories : PHP, Email, MySQL, Databases | | | POP3 Class Categories : PHP Classes, PHP, Email | | | A web-based php3 IMAP email client supporting address books, attachements (downloading and sending), LDAP searching, and much much more. Categories : Email, PHP, LDAP | | | email new items in db Categories : PHP, Email, Databases, MySQL, Beginner Guides | | | email validator check checker email e-mail email address Categories : PHP, Email, Regexps | | | Mail-lib provides a simple interface to the sendmail program. Note: you must actually have sendmail on your machine (sorry windows NT users). Categories : Algorithms, Email, PHP | | | Encoding data using PGP via PHP's proc_* functions Categories : Cryptography, Security, Email, PHP, PGP | | | Getting newsgroup with PHP Categories : PHP, IMAP | | | PHP based Contact email form with multiple recipients, text file based, supports departments. Categories : PHP, Email, Beginner Guides, Filesystem | | | HTTP Basic Authentication via POP3. Categories : Authentication, HTTP, Email, PHP | |
|
|
|