There are many other factors that can contribute to mail not getting to inboxes, including your own multiple failed testing attempts, so I suggest you consult each site's guidelines and don't ask me for help. On a UNIX system the MTA's "sendmail" interface assumes that recieved data will use UNIX line endings and will turn any \n to \r\n, so you must supply only \n to mail() on a UNIX system to avoid the MTA hypercorrecting to \r\r\n.These are just the couple technical issues that helped my case. If you use plain old \n on a Windows system, some MTAs will get a little upset.
I used Cpanel to create my domain key which automatically used all lowercase domain names in the key creation. In both cases, PHP's mail() function returned no error, but until I placed both emails, comma-separated, in the same line I was getting the following error:550 Messages should have one or no Cc headers, not 2. Note that there is a big difference between the behavior of this function on Windows systems vs. On Windows it delivers directly to an SMTP server, while on a UNIX system it uses a local command to hand off to the system's own MTA.
I found when sending email and using a camel case "-f [email protected] Domain Here. However it was accepted when I used "-f [email protected]". The upshot of all this is that on a Windows system your message and headers must use the standard line endings \r\n as prescribed by the email specs.
This parameter can't be cleaned by the mail() function.
So it is up to you to prevent unwanted \r or \n to be inserted into the values you put in there.
They will also most likely break if the body of the message contains more than 1000 consecutive characters without a \r\n.*Note that RFC 821 is a little more clear in defining:"line A a sequence of ASCII characters ending with a ."RFC 821 makes no distinction between header lines and message body lines, since both are actually transmitted during the DATA phase.
Bottom line, best practice is to be sure to convert any bare \n characters in the message to \r\n.* "The maximum total length of a text line including the Since lines in $additional_headers must be separated by \n on Unix and \r\n on Windows, it might be useful to use the PHP_EOL constant which contains the correct value on either platform.
I hope this saves someone some time and headaches... qmail in particular will refuse outright to accept any message that has a lonely \n without an accompanying \r.
Be careful to not put extra spaces for the $headers variable. For qmail users, I have written a function that talks directly to qmail-queue, rather than going through the sendmail wrapper used by mail().
I was having delivery issues from this function to Gmail, Yahoo, AOL, etc.
I used the notes here to figure that you need to be setting your Return-Path to a valid email to catch bounces.
Otherwise you just created a potential spam distributor.