bootneck2222
asked on
php mail putting random spaces in email output
Hi,
The script below opens a .csv file replaces the commas and new lines and then emails the output in HTML format. The problem is, on receiving the email it has a random space in the text, for example:
column1|column2|column3|co lumn4|colu mn5|column 6
column1|column2|column3|co lumn4|colu mn5|column 6
column1|column2|co lumn3|column4|column5|colu mn6
column1|column2|column3|co lumn4|colu mn5|column 6
column1|column2|column3|co lumn4|colu mn5|column 6
This space roughly appears every 980 characters (with spaces) - This is using MS Outlook.
Writing the variable $new_file to a file and displaying to screen don't show up this issue. Any help would be greatly appreciated.
Thank you.
The script below opens a .csv file replaces the commas and new lines and then emails the output in HTML format. The problem is, on receiving the email it has a random space in the text, for example:
column1|column2|column3|co
column1|column2|column3|co
column1|column2|co lumn3|column4|column5|colu
column1|column2|column3|co
column1|column2|column3|co
This space roughly appears every 980 characters (with spaces) - This is using MS Outlook.
Writing the variable $new_file to a file and displaying to screen don't show up this issue. Any help would be greatly appreciated.
<?php
$file = file_get_contents("../upload/$filename);
$search = array(",", "\r\n");
$replace = array("|", "<br>");
$new_file = str_replace($search, $replace, $file);
file_put_contents("/tmp/maildebuglog.txt",$new_file);
mail($address, 'Email Subject', $new_file,
"To: $user <$user@somedomain.com>\n".
"From: $admin <$admin@somedomain.com>\n".
"MIME-Version: 1.0\n".
"Content-type: text/html; charset=iso-8859-1" . "\n");
echo "$new_file";
?>
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks elvin66 for answer and introducing me to the nl2br function.
You're welcome. Just keep in mind that nl2br() only adds the <br> element into the text but does not remove the newline characters so you need to do a str_replace to remove them (if you need to).
Good luck
Good luck
http://stackoverflow.com/questions/11794698/max-line-length-in-mail
The normal method for content that doesn't have a line length like images is to use MIME boundaries and chunked base64 encoding which all mail clients understand. That is also how attachments are included in emails. If you specify it properly, you can put the whole message in base64 encoded format and completely get around line length problems.