no line breaks in plain text emails – PHP

  php

Q(Question):

I’m using the mail($MailTo, $Subject, $Body, $headers) function to
send out plain text emails, with the message/body being entered via a
form. When the email arrives, the message is displayed as a continuous
line, without carriage returns or line breaks.
I have tried inserting a number of different headers but always with
the same results. Can the problem be fixed with headers?

This only happens on Outlook/Windows XP – other setups show the email
fine!

Thanks…

A(Answer):

chokky wrote:

This only happens on Outlook/Windows XP – other setups show the email
fine!

Try this (just fishing):

<?php
// …
$Body = str_replace("\n", "\r\n", $Body);
$headers .= "\r\nContent-Type: text/plain";
mail($MailTo, $Subject, $Body, $headers);
?>

–= my mail box only accepts =–
–= Content-Type: text/plain =–
–= Size below 10001 bytes =–

A(Answer):

I noticed that Message-ID:
<5a**************************@posting.google.com > from chokky contained
the following:

When the email arrives, the message is displayed as a continuous
line, without carriage returns or line breaks.

http://uk2.php.net/wordwrap


Geoff Berrow (put thecat out to email)
It’s only Usenet, no one dies.
My opinions, not the committee’s, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/

A(Answer):

> Try this (just fishing):

<?php
// …
$Body = str_replace("\n", "\r\n", $Body);
$headers .= "\r\nContent-Type: text/plain";
mail($MailTo, $Subject, $Body, $headers);
?>

Thanks. Good suggestion – but this forces an extra break between
lines. Any other ideas welcome!

A(Answer):

chokky wrote:

Try this (just fishing):

1 <?php
2 // …
3 $Body = str_replace("\n", "\r\n", $Body);
4 $headers .= "\r\nContent-Type: text/plain";
5 mail($MailTo, $Subject, $Body, $headers);
6 ?>

Thanks. Good suggestion – but this forces an extra break between
lines. Any other ideas welcome!

change line 3:
$Body = preg_replace("\r?\n", "\r\n", $Body);

A(Answer):

> change line 3:

$Body = preg_replace("\r?\n", "\r\n", $Body);

Tried this too but no joy. Should I give up yet…?!

A(Answer):

chokky wrote:

Tried this too but no joy. Should I give up yet…?!

Can you post a complete mail with all the headers? — well … we could
without the Received:, X-*:, and a lot of others 🙂

–= my mail box only accepts =–
–= Content-Type: text/plain =–
–= Size below 10001 bytes =–

LEAVE A COMMENT