LOTUSMS
LOTUSMS

Reputation: 10240

\n is not giving me a new line in my HTML

I'm writing a PHPEmailer file and I have isHTML set to true and I also have this to format my output:

$mail->Body = 
    "Name: " . $_POST['quote_name'] . 
    "\r\n\r\nCompany: " . $_POST['quote_company'] . 
    "\r\n\r\nPhone: " . $_POST['quote_phone'] . 
    "\r\n\r\nAddress: " . $_POST['quote_address'] . 
    "\r\n\r\nCity: " . $_POST['quote_city'] . 
    "\r\n\r\nState: " . $_POST['quote_state'] . 
    "\r\n\r\nZip: " . $_POST['quote_zip'] . 
    "\r\n\r\nInspirational Link: " . $_POST['quote_link1'] . 
    "\r\n\r\nInspirational Link: " . $_POST['quote_link2'] . 
    "\r\n\r\nInspirational Link: " . $_POST['quote_link3'] . 
    "\r\n\r\nInspirational Link: " . $_POST['quote_link4'] . 
    "\r\n\r\nProject Details: " . stripslashes($_POST['quote_details']);

But the email is coming out like this:

Name: John Doe Company: Coca Cola Phone: 5552345678 Address: 123 Main St City: New York State: NY Zip: 17011 Inspirational Link: Inspirational Link: Inspirational Link: Inspirational Link: Project Details: a sample text

What I want is each of those fields in its own line

Upvotes: 4

Views: 107

Answers (5)

Kevin Kopf
Kevin Kopf

Reputation: 14195

When you set isHTML into true for PHPMailer, it would not take effect at output time, as you state in the comments to your question. It only sets the flag to send a header section indicating the e-mail is an HTML one: Content-type:text/html;, nothing else.

So what you actually need to do is to replace all your \r\n with <br> tag, otherwise you don't get your line breaks.

Upvotes: 3

Renuka Deshmukh
Renuka Deshmukh

Reputation: 998

</br> is used to insert line breaks in HTML.

You can try it out here.

Upvotes: 1

Panda
Panda

Reputation: 6896

You can use <br/> instead of \r\n\r\n, since HTML is enabled.

If you want to use \r\n\r\n, you'll need nl2br():

<?php
    Body =  nl2br("\r\n\r\nCompany: ");
?>

Upvotes: 2

Joel
Joel

Reputation: 324

Your email is set to html. Us a br tag instead.

"<br>Company: " . $_POST['quote_company'] .

Upvotes: 2

Tim Penner
Tim Penner

Reputation: 3541

\r\n in HTML doesnt mean anything; you need a <br> tag instead

edit:

\r\n could still be useful for readability of the source HTML, but it will not produce line breaks in the HTML output

Upvotes: 2

Related Questions