php adding line breaks to emails

Associate
Joined
28 Apr 2007
Posts
27
Location
Colchester, UK
Hi

I've recently uploaded a script which sends email via php's mail() function - no problems, apart from when the script runs on my live server it's adding an extra line break to every line.

I've tried replacing \n\r and manually hitting enter in my variable, but it always seems to add an extra line break to the string when it sends the email.

Does anyone have any ideas why this would happen? Everything was fine on my development setup locally.

Many thanks
 
Something about the php.ini file rings a bell!

I have recently started using the mail() function with PHP and I didn't notice an extra line break.

Where exactly is the break occuring, in the mail or the script? And are you using POST or GET on the form...I presume it is a form.
 
I have a default email which is stored in a variable and printed to a textarea. Then the form is posted and the raw post from the text area is put into the body of the email. (I know this isn't best practice but this part of the site is admin only).

This means that:

Code:
Line
Line

Line
Line

comes out

Code:
Line

Line


Line

Line

Any ideas?
 
Just found this fix:
Code:
$input = $_POST['textarea'];
$input = str_replace("\r\n", "\x00", $input);
$input = str_replace("\r", "\x00", $input);
$input = str_replace("\x00", "\n", $input);

Seems to do the trick :)

Thanks for your help, much appreciated.
 
No Problem.

If you want to use UBBC Code for formatting email you can also use that fix, it just needs modifying. It is a vary good script.
 
Back
Top Bottom