PHP mailing problem

I want to format the mail content to show the content on a different line. here is my contetn post. bu \ n and \ r doesn't work in this case. it just displays all content on one line.

$message = 'Thank you for using . We really appreciate your business.'."\r\n".'If you are making your payment by mail, please make the check out to "blah blah" and send it to:'."\n".'blah blah '."\n".'blah blah'."\n".'San Gabriel, CA 91776'."\n".'Please see the attached invoice in PDF format for easy saving & printing purposes.';

$attachment = chunk_split(base64_encode($pdfdoc));
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$headers .= $message.$eol.$eol;
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/pdf; name=\"".$filename."\"".$eol;
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";
mail($_POST['add6'],$subject, $message, $headers);

      

How can i do this?

+2


source to share


4 answers


You are telling the email client that the message is HTML, so the CR LF combination will be treated like any other spaces.

To fix this, change the content type to show that you are sending a plain text email



$headers .= "Content-Type: text/plain; charset=\"iso-8859-1\"".$eol;

      

Alternatively, turn your post into an HTML post - the easy way to do this in your case is to run it through nl2br to turn newlines into tags<br>

+12


source


Yes you have Content-Type: text/html

, so CR LF is treated as a space. Post it as Content-Type: text/plain

or call it nl2br

in your content.



+5


source


Your content type is HTML, so you should use br or p tags instead of strings.

+1


source


For \ n to work, it must be double quotes, not single quotes. "\ n" is the correct thing, "\ n" is wrong and will not work.

0


source







All Articles