views:

309

answers:

2

A few days ago I upgraded Php Mailer and now some email providers my messages mark as spam. This is what I see in the headers of the marked messages:

X-SpamTest-Info: {TO: header missing}

This is from my php file.

$mail->From       = $sender;
$mail->FromName   = $sender_name;
$mail->Subject    = $subject;
$mail->Body       = $body;
$mail->AddAddress($recipient,$recipient_name);
$mail->AddReplyTo($replyto,"No-Reply");

Dont know how to add "to" header and can't understand how it's possible that "to" is missing but email arrives to the correct "to" address...

+1  A: 

It's easy for mail to be sent without a "To:" header, because there are actually two things going on here. The "To:" header is really only there for humans to look at - the actual delivery is controlled by what is called the "envelope". When you send your message in a normal mailer, it initiates an SMTP conversion where it takes the addresses listed in the "To" header, the "CC" header, and the "BCC", strips off the BCC header, and it says to the SMTP receiver "RCPT TO: address1, address2, ..." and the SMTP receiver knows who to send it to without looking at the headers. It only looks at the headers to do spam checking, because mail that is missing To headers often indicates spam.

If there wasn't an envelope like that that was accessible to the mail transfer agents but not the end users and their mail user agents, it wouldn't be possible to use BCC.

I don't know the syntax of PHP Mailer, but does it support a "$mail->To" setting?

Paul Tomblin
There is no such function "to" in Php Mailer. This is their example code: $mail->AddReplyTo('[email protected]', 'First Last'); $mail->AddAddress('[email protected]', 'John Doe'); $mail->SetFrom('[email protected]', 'First Last'); $mail->AddReplyTo('[email protected]', 'First Last'); $mail->Subject = 'Test'; $mail->AltBody = 'Alt Body'; $mail->MsgHTML(file_get_contents('contents.html')); $mail->AddAttachment('images/phpmailer.gif'); // attachment $mail->Send();
Guanche
A: 

A few bullet points from a previous answer:

  • Most important: Does the sender address ("From") belong to a domain that runs on the server you send the E-Mail from? If not, make it so. Never use sender addresses like [email protected]. User reply-to if you need replies to arrive at a different address.

  • Is your server on a blacklist (e.g. check IP on spamhaus.org)? This is a possibility when you're on shared hosting when neighbours behave badly.

  • Are mails filtered by a spam filter? Open an account with a freemailer that has a spam folder and find out. Also, try sending mail to an address without any spam filtering at all.

  • Do you possibly need the fifth parameter "-f" of mail() to add a sender address? (See mail() command in the PHP manual)

  • If you have access to log files, check those, of course.

  • Do you check the "from:" address for possible bounce mails ("Returned to sender")? You can also set up a separate "errors-to" address.
Pekka
If you must use a fake `From:` header, add a `Sender:` header which is from your domain. This is what Gmail does when it fakes from headers. It works.
TRiG