Zend_Mail sent email is treated as SPAM
Asked Answered
C

1

6

Please tell me what I am doing wrong. I am sending an email using the Zend_Mail class like this:

$message = <<<STR
You have a new invoice!

Sign in to your clientarea to see it.

Best regards,

Company name
STR;

$mail = new Zend_Mail();
$mail->setBodyText($message);
$mail->setFrom('[email protected]', 'Company.com');
$mail->addTo('[email protected]', 'Client Name');
$mail->setSubject('You have a new invoice!');
$mail->send();

It is received as a spam though. There are other applications such as Webmin on my server and emails they send is not treated as SPAM.

Charger answered 11/9, 2010 at 18:19 Comment(3)
possible duplicate of PHP:How to avoid a system generated email going into spam?Breannabreanne
See also the linked questions in that duplicateBreannabreanne
Adding Reply-To header solved the problem.Charger
C
9

I have solved this by adding these lines:

$mail->setReplyTo('[email protected]', 'Company');
$mail->addHeader('MIME-Version', '1.0');
$mail->addHeader('Content-Transfer-Encoding', '8bit');
$mail->addHeader('X-Mailer:', 'PHP/'.phpversion());

The critical line seems to be adding Reply-To header. Without that it would always go to SPAM. Once I set the Reply-To header email clients stopped treating it as spam.

Charger answered 12/9, 2010 at 11:42 Comment(2)
What is the from header set to now?Breannabreanne
[email protected], reply to is [email protected].Charger

© 2022 - 2024 — McMap. All rights reserved.