I know there has been some discussion of problems with outgoing emails generated by Drupal. I've searched around the forum and I don't think that my problem fits those previously discussed. It also may not be a problem so much as the result of my poor PHP knowledge.
Anyway, I'm basically able to send using mail() in user.module just fine. The only problem has to do with terminating the MIME encoding information before the address headers ($headers) are returned. I'm unable to place a \n at the end of the first string or at the beginning of the $headers string (messages are either not sent or received by servers), with the result that the first part of $headers (From:, in my case) remains on the same line as the "...-encoding: 8bit", like this:
Content-Transfer-Encoding: 8BitFrom: thomas@mydomain.com
The result is that the actual From: address attached to the email is the generic server setting from php.ini. Ugly and midleading.
So here are the relevant lines in my user.module:
return mail($mail, mime_header_encode($subject), str_replace("\n", '', $message), "MIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8; format=flowed\nContent-transfer-encoding: 8Bit" . $headers);
and
$headers = "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from";
The bottom line question, I think, is why are messages with a \n at the start or end of a string rejected?