Hi everyone. I have my own PHP framework. 3 months of hard work. I have done 7 websites with framework, but two days ago, I have found strange bug.
I am using this function:
The solution I have found is to replace \r\n with only \n. In 6 servers, my mail sending was correct, but in one, mail headers was seen in message body. Like:Code:/**
* Send mail
*
* @param string $To Send email to
* @param string $From Send from
* @param string $Subject Email subject
* @param string $Body Email body
* @param string $Encoding Encoding to use
* @param string $Type Email type (html or plain)
* @return void
* @access public
*/
if (!function_exists("send_mail"))
{
function send_mail($To, $From, $Subject, $Body, $Encoding = "iso-8859-1", $TYPE = "plain")
{
$Headers = "From: " . $From . "\r\n";
$Headers .= "Reply-To: " . $From . "\r\n";
$Headers .= "Return-Path: " . $From . "\r\n";
$Headers .= "Content-Type: text/" . $TYPE . "; charset=" . $Encoding . "\r\n";
$Headers .= "X-mailer: ReekenX WForce Framework\r\n";
mail($To, $Subject, $Body, $Headers);
}
}
Code:From: sender@sender.com Reply-to: sender@sender.com (other headers seen here) Message text
Can anybody explain why email sending with \r\n is bad, and with \n is right?
Sorry for my poor english![]()
According to the RFC2822, all mail headers should be terminated with a CRLF (carriage return line-feed), so it is not an issue with your code. I could be wrong, but I have read some linux servers replace a LF with a CRLF automatically, thus creating a double CR which results CRCRLF [\r\r\n] and thus is invalid.
PHP themselves recommend \r\n...however, they also state:
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
Many thanks to everyone!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks