php set email user agent
I have an application that sends verific开发者_如何学Cation emails to people account email address, but sometimes it goes into their spam filter, after an analysis on the email we found that one of the reasons is because of having no user agent name.
is there a way to set this using php's default email sender?
thanks
I wrote a exhaustive "what to do if auto-generated mails get swallowed by the spam filter" a few years ago. Unfortunately, it's in german, but one aspect I remeber from the research I did for it is that spam filters can react very pickily to X-Mailer signatures that point towards a programming language / script / bulk E-Mailer. You may want to pretend to be a normal mail program like Outlook to make sure the E-Mail gets through.
The only user agent setting in PHP is user_agent
, but this setting is only used for HTTP requests. You can pass additional headers to the mail()
function to accomplish this:
mail(
'to@example.com',
'Subject',
'Message Body',
"From: from@example.com\r\nX-Mailer: PHP"
);
You need to set a header that identifies your program. As you can see in the php manual for mail the fourth paramter allows you to include headers. The RFC identifies both "Mailer", "X-Mailer" and "Sender" as the agents, so which one to use I will leave up to you (wikipedia notes that X-Mailer is ofte used by clients).
An example:
$headers = "X-Mailer: MyApp\r\n";
$succcess = mail(€to, $subject, $message, $headers);
Headers like X-Mailer (all beginning with X-)
are extra headers, and do not define User Agent header.
You should define header: "User-Agent".
See sources your messages which you are sent from email client.
精彩评论