I configured my Windows Server 2016 with IIS to pickup mail() from php and send them to stmp.sendgrid.net.
To test my configuration, I can telnet my localhost and send email from there with no problem.
However, if I send the email via a mail() php function, SendGrid receive the request, but blocks it with this error:
REASON550 5.7.1 [167.89.55.39 11] Our system has detected that this message is not RFC 5322 compliant: Multiple 'From' headers found. To reduce the amount of spam sent to Gmail, this message has been blocked. Please visit https://support.google.com/mail/?p=RfcMessageNonCompliant and review RFC 5322 specifications for more information. h190si13823586ite.62 - gsmtp
So the error is because it's IIS sending the email to sendgrid and because of that, it's beeing marked as a spam.
What could cause this?
Apparently you need a detailed header when using PHP mail() and not when you telnet.
For PHP mail() at mininum:
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: your@email.com" . "\r\n";