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
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";

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

$headers = "From: xxxx@xxxxx.com \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.

Link to comment
Share on other sites

This line

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

says that you're sending HTML formated email. Since this is the case, you need to use the "<br>" tag to get a newline to appear.

 

Ken

 

Nice catch kenrbnsn. I didn't even notice that.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.