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.
Newline showing up on screen but not in email
If your email is HTML formatted then that would affect presentation of newlines.
PHP break line .\n isn't working in email body. Lines are dissapearing
You are base64encoding the line endings aswell
So the actual output would not have \n\r
Try this:
$string .= $sender_name."\r\n";
$string .= $sender_number."\r\n";
$string .= $sender_message."\r\n";
$body .= base64_encode(chunk_split($string)); // I think since your transfer encoding is base64, it will not respect the line endings added by the chunk_split not sure tho so be sure to encode it all with base64
EDIT:
Given your code:
$body = $sender_name. "\n";
$body = $sender_number. "\n";
$body = $sender_message. "\n";
On each of these lines you are not appending the string but assigning it a new value; use .=
instead of assignment operator
Some occurrence of \r\n not working in text email encoding in one of the test environments
Thanks for your solution @maxBilbow.
The issue was due to Outlook changing the format and ignoring some of the line changes and spaces it assumed unnecessary.
Adding 3 or more spaces at the start of each line fixed the issue.
replaced public String EOL = "\r\n"; with public String EOL = "\r\n ";
Insert a line break in mailto body
I would suggest you try the html tag <br>
, in case your marketing application will recognize it.
I use %0D%0A
. This should work as long as the email is HTML formatted.
<a href="mailto:email@mycompany.com?subject=Subscribe&body=Lastame%20%3A%0D%0AFirstname%20%3A"><img alt="Subscribe" class="center" height="50" src="subscribe.png" style="width: 137px; height: 50px; color: #4da6f7; font-size: 20px; display: block;" width="137"></a>
You will likely want to take out the %20 before Firstname, otherwise you will have a space as the first character on the next line.
A note, when I tested this with your code, it worked (along with some extra spacing). Are you using a mail client that doesn't allow HTML formatting?
Plain text email next line doesn't work even with \r\n
You need to specifically declare content type to html to use html statements
$message_string = "\r\n";
$message_string .= 'Content-Type: text/html; charset=ISO-8859-1"';
$message_string .= "\r\n";
$message_string .= $Message;
Now your break statements will take effect.
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.
Related Topics
Get the Latest File Addition in a Directory
PHP Date Format /Date(1365004652303-0500)/
MySQL No Connection Could Be Made Because the Target MAChine Actively Refused It
PHP Curl Curlopt_Ssl_Verifypeer Ignored
Determining What Classes Are Defined in a PHP Class File
How to Write JavaScript Code Inside PHP
How to Delete a Folder with Contents Using PHP
Using Simplexml to Read Rss Feed
Rgb to Closest Predefined Color
PHP Foreach Loop Through Multidimensional Array
Codeigniter - Best Place to Declare Global Variable
PHP Recursion to Get All Possibilities of Strings
How to Detect an Incoming Request (With PHP Script) from a Cname Subdomain
How to Convert Soap Response to PHP Array
How Get Value for Unchecked Checkbox in Checkbox Elements When Form Posted