Before I had the following lines in my script:
mail($to, $sub, $mes, "From: \"".$from."\" <".$from.">\r\nReturn-Path: <".$from.">\r\nContent-Type: text/plain; charset=utf-8\r\n");
In this case only the last line of headers appeared as a part of message text:
Content-Type: text/plain; charset=utf-8
Message text
Then I changed headers to:
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=utf-8\r\n";
$headers .= "To: ".$to." <".$to.">\r\n";
$headers .= "From: ".$from." <".$from.">\r\n";
$headers .= "Reply-To: ".$from." <".$from.">\r\n";
When I did it, all headers were visible as a part of message.
When I added:
$headers .= "Return-Path: ".$from." <".$from.">\r\n";
all emails came from apache@myhostname ignoring "from" address.
Note: If messages are not received, try using a LF (\n) only. Some poor quality Unix mail transfer agents replace LF by CRLF automatically (which leads to doubling CR if CRLF is used). This should be a last resort, as it does not comply with » RFC 2822.
Messages are always received. The problem is the way how they are received.
What does it mean "poor quality mail transfer agents"???
Now when I have \n instead of \r\n, everything works fine, but I would like to fix this problem so that mail are delivered properly from any server and to any server.