Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending DKIM signed e-mail to Outlook.COM via PHP

I have a mail server working well with SPF, DKIM and reverse DNS configured. I can send e-mails to Outlook.com using something like:

echo "This is only a test" | mail [email protected]

The problem occurs when I try to send e-mails via PHP using the same server:

$header .= "Return-Path: Some User <[email protected]>\r\n";
$header .= "From: Some User <[email protected]>\r\n";
$header .= "Content-Type: text/plain; charset=iso-8859-1\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "User-Agent: Some User Mail Sender\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n";

mail("[email protected]","My title", "Message body", $header);

I tried to verify my message using appmaildev.com and the report says:

DKIM result: fail (wrong body hash: <*** body hash ***>)

Even with this error, Outlook.com says it passed DKIM verification, but all messages sent by PHP mail function go to junk folder. Here are examples of messages sent directly via Bash and via PHP: http://pastebin.com/ndXJszic

Can anyone help me?

Thanks.

EDIT After removing \r from headers, the DKIM body hash error is gone. But I still can't send e-mails to Outlook...

like image 500
user1858109 Avatar asked Nov 27 '12 23:11

user1858109


2 Answers

This could be a permission issue.

Your web server normally runs as a different user than when you use mail on the command line, so setting the From: header will create additional warning headers in the outgoing email.

There's a file you can modify on your server called /etc/mail/trusted-users. Make sure that the user apache (or whatever user your php script is running as) appears in that file; if not, add the user name and then reload sendmail.

Example contents of /etc/mail/trusted-users:

# trusted-users - users that can send mail as others without a warning
# apache, mailman, majordomo, uucp, are good candidates
apache
like image 172
Ja͢ck Avatar answered Nov 16 '22 15:11

Ja͢ck


First is impossible to be sure that an email will not be marked as spam, the only way is that the person who receive the email add the sender address in a white list.

SPF and DKIM are only to guarantee that the email comes from that domain or email, but not to guarantee that it is not spam.

The antispam system in outlook.com as many others check a lot of things, for example the sender ip address, how many email comes from that ip per hour, the content of the email (text, links), reputation, etc.

In your example you don't show the body content, maybe it's different and for this reason one email is marked as spam and the other it's not.

like image 1
Dany Flores Avatar answered Nov 16 '22 14:11

Dany Flores