I've got a newsletter that sends out posts in html format, but it keeps showing the return and newline characters (\r\n) between paragraphs once it gets to the inbox. To try and filter out these characters I use $body = str_replace("\n", "", $body); $body = str_replace("\r", "", $body); Then I send the email with these parameters: mail($to, $subject, $body, 'From: ' . "\r\nContent-Type: text/html", '-f '. 'email@address.com') Any suggestions?
Try it $body = nl2br($body); $body = str_replace("<br />", "", $body); The tag "<br />" can be also "<br>". It depends on PHP version.
Technically there is no such thing as return/newline characters in HTML. They only exist as part of headers or textual content. I'm guessing that what you're sending simply isn't proper HTML. Otherwise I can't think of another reason why they'd appear magically, unless you have some filtering going on beforehand that's converting the HTML to text.
Okay, fixed it afterwords. Originally I assigned the $_POST['body'] variable to $body. Then when I was modifying the html template to contain the newsletter I used the code $template_source = str_replace("{CONTENT}", $body, $template_source); after which I would assigned the $template_source to $body and send the email. so instead I used $template_source = str_replace("{CONTENT}", $_POST['body'], $template_source); Don't know why, but this fixed the problem.
make sure correct headers are used: $headers = "Date: ".date('r')."\n"; $headers .= "Return-Path: ".something@yourdomain.com."\n"; $headers .= "From: ".$from."\n"; $headers .= "Message-ID: <".md5(uniqid(time()))."@yourdomain.com>\n"; $headers .= "X-Priority: 3\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Transfer-Encoding: 8bit\n"; $headers .= 'Content-Type: text/html; charset="iso-8859-1"'."\n";