Whitespace in email issue
I'm experiencing a strange problem and difficult to diagnose because
it's random. I have built an application that sends out an email with a nice amount of text (don't have exact char count, but could get it).On the html email, a random whitespace appears in the content.
See below for examples of how the space w开发者_JS百科anders and is random:
1- "Th ere are several things being discussed in this email."
2- "There are se veral things being discussed in this email."
3- "There are severa l things being discussed in this email."
This whitepace issue also happens for links. Found this issue in hotmail and gmail so far.
Anybody have any ideas?
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset=utf-8\r\n"; $header .= "From: abc \r\n"; $subject = "abc"; $mail_body = "Hello!"; $mail_body .= "content"; mail($email_address, $subject, $mail_body, $header);That is the code to give you an idea roughly..
You might be getting this issue when you have a long line and it is automatically broken to then next line after the RFC's 72 char recommendation.
where
hey lots of stuff here Jimmy will probably be way longer than 72 characters
will become
hey lots of stuff here Jimmy will probably be way longer than 72 charac
ters
And which would render in a HTML e-mail as
hey lots of stuff here Jimmy will probably be way longer than 72 charac ters
If you "view source" of the email message, is the space in the source, or is it just appearing in the rendered (visible) text? First thing I would do is look at the email source to see what's up - I wouldn't trust the rendered/visible text for debugging this.
Also, you said "on the html email". That implies that you might be sending a plain text version either to different people, or maybe to the same people (as a multipart message). If that's the case, can you confirm that it's not there also?
As Terry said, can you post some of the code, specifically the code that sends the message and the some/all (if it's short) of the code that builds the message text up for sending?
It would help if you posted offending code, as there are many things that could cause this.
Do you use mail() or phpmailer or swiftmailer? Are your emails multipart or text only? Do you parse your templates yourself?
If it's HTML, please post the HTML code that clients receive, etc.
Is it possible that there are trailing/heading spaces when you concatenate strings? Try "trim"ming on each element you add to your $mail_body like:
$mail_body .= trim($content);
The issue, as I understand it, is from your lines running too long. The PHP mailer adds line breaks (and with them, white space) to break up long lines.
My recommendation for this is to add "\r\n" to the end of your lines. This purposely adds line breaks to your text, keeping the mailer from doing so on its own. eg:
There are several things being discussed in this email.\r\n
notice double quotes are used here. Single quotes will simply append \r\n to your text.
For reference: This question answered the same question when I had it.
精彩评论