PHP
--
Questions
--
Followers
Top Experts
I Â use Mozilla Thunderbird 1.5 as e-mail client.
When I receive some plain-text e-mails sent by the PHP mail() function the e-mail message is displayed with double or quadruple line-breaks.
In other words, this issue only arises, as far as I know, with plain-text e-mails sent using PHP mail() function.
I have done some testing on this:
Outlook Express --> text/plain --> Thunderbird (OK)
php mail() --> text/plain --> Outlook Express (OK)
php mail() --> text/plain --> Thunderbird (outlined below)
I tested this using the following as the body of the php mail:
<?php
Â
 $email_message = "
 $greeting\n
 You have received a message from $Name <$EMailAddr>.\n
 Timestamp: $timestamp
 IP Address: $ip
 Name: $Name\n
 $MessageTitle:
 ---------------------
 $Message
 ---------------------\n
##########################
Sample text sample text sample text sample text
 sample text sample text sample text sample text sample text.
##########################
";
?>
Everything was formatted ok except for the [$Message] part which came from a <textarea> inside a HTML form.
Every line break was doubled. I've pasted the e-mail as received by Thunderbird below - 1 line break (hard return) changed to 2 and 2 changed to 3 ...
Does anyone have any ideas? Is this a Thunderbird related issue or a php mail() issue?
Thanks for your input!
==========================
 Good morning!
 You have received a message from Julian <[EDITED]>.
 Timestamp: 2006-01-30T07:47:56+01:00
 IP Address: 159.134.184.134
 Name: Julian
 Test:
 ---------------------
 Just testing...
Testing.
Testing...
Testing
More testing
 ---------------------
##########################
Sample text sample text sample text sample text
 sample text sample text sample text sample text sample text.
##########################
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Hello
welcome
goodbye
PHP adds a newline character for each line break like above so using \n aswell is why you get that problem.
James
I know what you mean with the \n characters, but there are none in $Message.
The problem occurs only inside the two lines: (whether I leave out the "\n" in the rest or not)
 ---------------------
 Just testing...
Testing.
Testing...
Testing
More testing
 ---------------------
fill in the blanks :)
<?php
$to = '';
$from = '';
$subject = 'just a test!';
$message = "
Hello
Goodbye
";
mail($to, $subject, $message, $from);
?>
Please post the email body you get back into here, tis should help diagnose a little easier if its related to the form or not.
BTW, what operating system?
also, are you using sendmail or SMTP or what?
James






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
I received the e-mail in both Outlook Express and Thunderbird...
The results were slightly different:
Thunderbird removed the first line and added 2 or three at the end of message.
Outlook Express added 2 at the beginning and 1 or 2 at the end.
=OUTLOOK EXPRESS=========
>
>
>
>Â Hello
>
>Â Goodbye
>
>
>
=======================
=THUNDERBIRD=============
>Â Hello
>Â
>Â Goodbye
>Â
>Â
>Â
>Â
=======================
>>Â what operating system?
Debian Sarge /GNU Linux, PHP 5.x, Apache 1.3
>>Â also, are you using sendmail or SMTP or what?
Pretty sure it's sendmail
>>Â $message = str_replace(array("\r\n","
I will test this and get back... Thanks!
Your str_replace() method seems to work...
The issue only seems to occur with text received from a textarea, so this could be applied to that...
Have you any idea if there is also a server-side configuration that can solve this issue?
I can apply your method no problem when I'm developing on PHP but there are a lot of e-mails that are sent automatically by software on my server - for example the control panel and the billing system. It would be a lot easier to configure server-side... Maybe php.ini?
Thanks,
Julian
James

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Some people may not notice the extra line breaks because most e-mail clients compensate for extra line breaks by removing them from the message. My guess is that that's why the messages looked normal in Outlook Express.
If you have access to a server with PHP do you think maybe you could try uploading a test page that will submit the text from a textarea to my email address?
You don't have to do this... Only if you have time and wish to do so... If you can't just let me know and I will close the question...
I have written the php and uploaded in txt format to my server just in case. It includes my e-mail address.
http://www.netlink.ie/testing/phpmail.php.txt
Thanks,
- Julian
You're right, the e-mail you sent me was formatted without extra line breaks:
==============
>Â first line
>Â
>Â third line
>Â
>Â fifth line
>Â
>Â
>
==============
wherea mine looks like:
==============
>Â first line
>Â
>Â
>Â
>Â third line
>Â
>Â
>Â
>Â fifth line
>Â
>Â
>
==============
So it must be a server issue...
Very strange... Or would it be a PHP version issue?






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Haven't really resolved this issue yet, but will keep trying.
If all fails I will just use the str_replace method you suggested...
I appreciate all your help!! Thanks!!
- Julian.
James
I don't know if you're still subscribed to this question...but I've made a very interesting discovery :-) ...
I've examined the e-mails as they come into Thunderbird and then compared them to the way they *should* be formatted...
This is what I found:
Every line in the e-mail that ends with a colon ":" is proceeded by 1 or 2 extra line break...
(It only happens when the ":" is at the end of a line, not if it's proceeded by text like
example: example)
Example: if this is the text for a plain-text e-mail -
==========================
Dear %%FULLNAME%%,
Your new hosting account has been created!
You should receive login details for your new account shortly.
If you are using an existing domain with your new account
you may need to change the nameserver information.
Our nameservers are:
NS1.EXAMPLE.COM
NS2.EXAMPLE.COM
If you wish to use your own nameservers you must setup
A-records and MX-records (for mail) to this IP address:
%%IPADDRESS%%
Your billing information can be accessed using following details:
%%USERLOGINURL%%
Username: %%EMAIL%%
Password: %%CLIENT_REAL_PASS%%
__________________________
Please contact us if you have any questions about your account.
==========================
Then this would be the e-mail when it arrives in the inbox:
==========================
Dear Name,
Your new hosting account has been created!
You should receive login details for your new account shortly.
If you are using an existing domain with your new account
you may need to change the nameserver information.
Our nameservers are:
NS1.EXAMPLE.COM
NS2.EXAMPLE.COM
If you
wish to use your own nameservers you must setup
A-records and MX-records (for mail) to this IP address:
195.137.213.66
Your billing information can be accessed using following details:
https://url
Username: username
Password: passwd
__________________________
Please contact us if you have any questions about your account.
==========================

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
But I don't think it's an issue with Thunderbird because I had a copy of the same message sent to Outlook Express and I looked at the message's source code there and it's the exact same... My guess is that Outlook Express just removes the extra line breaks automatically when displayed...
Also, this only happens with plain-text, HTML mail seems fine...
PHP
--
Questions
--
Followers
Top Experts
PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.