[RESOLVED] PHP mail inserting "rn" instead of carriage returns
with the following code emails are sent but if the user hits the enter key in the browser then in the email instead of the carriage return it puts the word rn. below is the complete mail code and worktobedone variable is the one that can have multiple lines and it the problem
Code:
if ($emailaftercreated != ""){
$to = $emailaftercreated;
$subject = "New Ticket";
$body .= '<html><body>';
$body .= '<h4>A New Ticket Has Been Created<h4>';
$body .= '<table rules="all" style="border-color: #666;" cellpadding="10" font size="2">';
$body .= "<tr bgcolor=#98AFC7><td><strong>Ticket #:</strong> </td><td>" . $recnum . "</td></tr>";
$body .= "<tr bgcolor=#98AFC7><td><strong>$UnitChangedTo:</strong> </td><td>" . stripslashes($unitnumber) . "</td></tr>";
$body .= "<tr bgcolor=#98AFC7><td><strong>Created Date:</strong> </td><td>" . date("m/d/Y") . "</td></tr>";
$body .= "<tr bgcolor=#98AFC7><td><strong>Call-In Date:</strong> </td><td>" . changeDate($callindate) . "</td></tr>";
$body .= "<tr bgcolor=#98AFC7><td><strong>Name:</strong> </td><td>" . stripslashes($customername) . "</td></tr>";
$body .= "<tr bgcolor=#98AFC7><td><strong>Phone:</strong> </td><td>" . stripslashes($phone) . "</td></tr>";
$body .= "<tr bgcolor=#98AFC7><td><strong>Address:</strong> </td><td>" . stripslashes($address) . "</td></tr>";
$body .= "<tr bgcolor=#98AFC7><td><strong>Assigned To:</strong> </td><td>" . stripslashes($assignedto) . "</td></tr>";
$body .= "<tr bgcolor=#98AFC7><td><strong>Work To Be Completed:</strong> </td><td>" . stripslashes($worktobedone) . "</td></tr></td></tr>";
$body .= "</table>";
$body .= "</body></html>";
$body=wordwrap($body, 72); //this should stop the random ! from appearing
$headers = "From: " . $emailfrom . "\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to,$subject,$body,$headers);
Re: PHP mail inserting "rn" instead of carriage returns
i found the issue and for those interested in the fix:
it turns out that i was striping slashes this variable in another process so i stopped that and replaced this code
Code:
stripslashes($worktobedone)
with this
Code:
nl2br($worktobedone)
because the rn was really \r\n that was being stripped and the nl2br code replace the \n with a <br> so the html looks correct now