Newline Not Working in PHP Mail

newline not working in PHP mail

Try to change your ' to " - php interprets a string inside single quotes as literals, whereas with quotes (") it will expand the \r\n to what you want.

More information: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.single

New lines (\r\n) are not working in email body

You need to use a <br> because your Content-Type is text/html.

It works without the Content-Type header because then your e-mail will be interpreted as plain text. If you really want to use \n you should use Content-Type: text/plain but then you'll lose any markup.

Also check out similar question here.

PHP new line break in emails

Try \r\n in place of \n

The difference between \n and \r\n

It should be noted that this is applicable to line returns in emails. For other scenarios, please refer to rokjarc's answer.

PHP mail line break problem

You're telling the email client the message is HTML, so the CR LF combination will be treated like any other whitespace.

To fix this, change the content type to show you are sending a plain text email

$headers .= "Content-Type: text/plain; charset=\"iso-8859-1\"".$eol;

Alternatively, turn your message into an HTML message - an easy way to do that in your case would be to run it through nl2br to turn the newlines into <br> tags

Creating A New Line In $body Of PHP Mail Function

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

Add line breaks in mail function php

To add line break you need to add "\n", not '\n'

Why newline \n is not working php form submission

You don't show the rest of your code, but I'd guess that you're calling $mail->isHTML(), in which case you line breaks will not be shown in a rendered message, regardless of whether they are \n or \r\n. Add <br> tags to your body, and note that you don't need to add any more line breaks because your string already contains them:

$mail->Body = "New application от,<br>
Name: $name<br>
Gender $gender<br>
Phone: $phone<br>
Email: $email<br>
Program: $program";

the following mail does not produce line breaks with double quotes

In html mails, you should use <br /> to add a line break.

All html parsers will ignore \n line breaks in the code.



Related Topics



Leave a reply



Submit