Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

phpmailer

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

like image 612
LOTUSMS Avatar asked Dec 25 '22 08:12

LOTUSMS


2 Answers

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.

like image 76
Alex Karshin Avatar answered Dec 28 '22 10:12

Alex Karshin


\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

like image 35
Tim Penner Avatar answered Dec 28 '22 10:12

Tim Penner