Jump to content

Line breaks in variables?


tcorbeil

Recommended Posts

Hello, I'm using this line to send an email...

 

mail($email2, "XXXX.com: Registration- Thank you.", $body, $headers);

 

Now the variable $body is quite long and needs to be formated..

 

so i tried this:

 

$body = "Welcome\nThis is a test\n1)blahblah\n2)blahblah";

 

Where the outcome i would expect is:

 

Welcom

This is a test

1)blahblah

2)blahblah..

 

 

obviously isn't formatting with '\n'...  any other ways to format in variables or am i chasing a ghost?

 

Thanks T.

 

Link to comment
https://forums.phpfreaks.com/topic/47448-line-breaks-in-variables/
Share on other sites

i think the function nl2br will work

 

you need to use it like this

 

<?php
$body = nl2br($body);
?>

 

 

That would be for printing to the browser or sending an HTML formatted email.

 

Try this:

 

$body = "Welcome\n"
        ."This is a test\n"
        ."1)blahblah\n"
        ."2)blahblah";

Thanks HeyRay but it is not working..

 

my actual code starts off as $body= "Hello.\n\n".$UserName." blahblahblah... and when I check my email, the format is:

 

Hello. Tim blahblahblah...

 

where I would expect:

 

Hello.

 

Tim blahblahblah...

 

..any other ideas?

T.

actually HeyRay, the full code for my email is..

 

$headers = "From: [email protected] \r\n";

$headers.= "Content-Type: text/html; charset=ISO-8859-1 ";

$headers .= "MIME-Version: 1.0 ";

/*notice there aren't any \r\n after the second two header additions. This is what made this version work correctly*/

mail($email2, "xxxx.com: Registration- Thank you.", $body, $headers);

 

does the the line "$headers.= "Content-Type: text/html; charset=ISO-8859-1 "; " have anything to do with formatting??

 

T.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.