note 24292 deleted from function.mail by aidan
| From: | aidan@php.net | Date: | Mon, 14 Feb 2005 02:02:15 +0000 |
| Subject: | note 24292 deleted from function.mail by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-84953@lists.php.net to get a copy of this message | ||
Note Submitter: mindplay(at)mindplay(dot)dk
----
I recently had to spend a lot of time finetuning a function for mail() which would work properly on
both Linux and Win32 server. Here's the wrapper function, which should solve all (or most) of
the common problems that beginners run into:
function send_mail($myname, $myemail, $contactname, $contactemail, $subject, $message) {
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
$headers .= "X-Priority: 1\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "X-Mailer: php\n";
$headers .= "From: \"".$myname."\"
<".$myemail.">\n";
return(mail("\"".$contactname."\"
<".$contactemail.">", $subject, $message, $headers));
}
This has been tested with both Linux (qmail) and Win32 (ezmts) mail servers, and worked perfectly
well. Note that the two headers "X-Priority" and "X-MSMail-Priority", can be
left out - but they will help overcome some of the more aggressive spam filtering systems (hotmail,
yahoo mail, ...) and ensures your mail is delivered.
Also note that you should use \n for new lines in the body of your message - not \r or \r\n ...
these don't work on all mail servers, but apparently \n does.
Finally, here's an example of using the function, sending an email from "the company"
to "the customer":
if (send_mail("Company", "person@company.com", "Customer",
"customer@server.com", "This is a test", "This is a test\nOne two three
four\nBlah blah blah\nThis is a test!")) {
print "SENT!";
} else {
print "FAILED!";
}