note 98591 deleted from function.mail by danbrown
| From: | danbrown@php.net | Date: | Fri, 25 Jun 2010 13:31:06 +0000 |
| Subject: | note 98591 deleted from function.mail by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-170408@lists.php.net to get a copy of this message | ||
Note Submitter: webmaster at jqueryin dot com
----
Although not a fool-proof method for preventing your emails from showing up in the target's
spam folder, the following should help. Simply specify a "From" email address in the
headers that matches your domain name. Simply use the function below and swap out
someUser@yourdomain.com for an email address within your domain.
<?php
/**
* Mail a user, abstracts out the headers so you don't have to.
*
* @author Corey Ballou
* @website http://www.jqueryin.com
*
* @param string $to The email address(es) of the receiver, can be comma delimited
* @param string $from The email address of the sender
* @param string $subject The subject of the message
* @param string $message The body content of the email
*/
function mailto($to, $from, $subject, $message) {
$headers = "From: someUser@yourdomain.com\r\n" .
'Reply-To: ' . $from . "\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: text/html; charset=utf-8\r\n" .
"Content-Transfer-Encoding: 8bit\r\n\r\n";
return mail($to, $subject, $message, $headers);
}
?>
Note that there are potential security issues with not validating the email address used in $from.
You can implement this on your own. A malicious user could throw in some newlines and additional
header strings (i.e. blind carbon copies).
If you still have email ending up in spam folders, the proper way to handle this issue is to address
the following:
1. Ensure your server's IP address isn't blacklisted from the email provider.
2. Create a valid and correct SPF record on your external DNS server.
3. Contact your domain's ISP to ensure your static IP has a correct reverse DNS record that
points back to your email server. This can usually be accomplished by the aid of your hosting
provider.
Good luck!