Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating A New Line In $body Of PHP Mail Function

Tags:

forms

php

email

I've got the PHP mail(): function working for a form I'm using on my site. I am now trying to format the $body attribute to look nicer and more organized when I receive the subsequent e-mail.

I've tried \n and I've tried
and both give me

Here's the snippet of the code that I'm working with (I think it's just a matter of syntax that I'm doing wrong):

if(!empty($brandname) && !empty($firstname) && !empty($lastname) && !empty($email) && !empty($goals) && !empty($bio)){
        $to = '[email protected]';
        $subject = 'Submission Form';
        $body = 'Brand Name: '.$brandname.'<br />Name: '.$firstname.' '.$lastname.'<br />Email: '.$email.'<br />About the Company:'.$bio;
        $headers = 'From: '.$email;

It's just displayed the <br /> as text in the e-mail I receive. It was the same when I used \n (which I'm assuming is actually the right way to do it). What am I doing wrong? Thanks.

like image 449
MillerMedia Avatar asked Jan 08 '12 22:01

MillerMedia


People also ask

How do I put a new line in the body of an email in PHP?

Answer: Use the Newline Characters ' \n ' or ' \r\n ' You can use the PHP newline characters \n or \r\n to create a new line inside the source code.

How do you insert a new line in an email?

In your Send Outlook Mail Message activity you have selected the IsBodyHtml in the property as True, so you can use "<br />" tag where you need NewLine. This is a html tag for a new line.

How do you code a new line in PHP?

The nl2br() function inserts HTML line breaks (<br> or <br />) in front of each newline (\n) in a string.

How do you insert a line break in plain text email?

You can insert a break into plaintext emails using {! BR()} .


1 Answers

You must place \n in double quotes " not between single quotes ' If you want that this sequence would be interpreted as a new line (line feed 0x0A) character

Take a look at this php documentation:

http://php.net/manual/en/language.types.string.php

like image 198
Abraham Covelo Avatar answered Sep 30 '22 11:09

Abraham Covelo