Edward Posted January 13, 2008 Share Posted January 13, 2008 Hi, Has anyone ever experienced this? I have noticed it a couple of times in different emails sent by different domain. I'll send an email using mail() where the body of the email could be something like 'Hello, this is a test', however when I receive it it reads 'Hello thi !s is s test'. Note the unwanted space followed by a exclamation mark. There is nothing in the source php to create this and if i re-send the email it happens again in the same place. Is this a known problem, is there a remedy? Quote Link to comment https://forums.phpfreaks.com/topic/85808-emails-sent-via-mail-are-received-with-unwanted-spaces-and-exclamation-marks/ Share on other sites More sharing options...
monkeytooth Posted January 13, 2008 Share Posted January 13, 2008 Show us your code... also where is the data coming from for the email to be sent? A form? Quote Link to comment https://forums.phpfreaks.com/topic/85808-emails-sent-via-mail-are-received-with-unwanted-spaces-and-exclamation-marks/#findComment-437927 Share on other sites More sharing options...
Edward Posted January 13, 2008 Author Share Posted January 13, 2008 The data being affected isn't from a form, it's from the source code. It's contained it variables which, if true, will then be included in the email, like so: $body1 = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><title></title><meta http-equiv="content-type" content="text/html;charset=utf-8" /><meta http-equiv="Content-Style-Type" content="text/css" />'; $body1 .= '<body>'; $body1 .= '<p>'; if(isset($_POST['file1'])) { $body1 .= 'File 1 (<a href="'; $body1 .= 'http://www.domain.com/file1.pdf'; $body1 .= '">http://www. domain.com/file1.pdf</a>'; $body1 .= ')<br />'; } if(isset($_POST['file2'])) { $body1 .= 'File 2 (<a href="'; $body1 .= 'http://www.domain.com/file2.pdf'; $body1 .= '">http://www. domain.com/file2.pdf</a>'; $body1 .= ')<br />'; } if(isset($_POST['file3'])) { $body1 .= 'File 3 (<a href="'; $body1 .= 'http://www.domain.com/file3.pdf'; $body1 .= '">http://www. domain.com/file3.pdf</a>'; $body1 .= ')<br />'; } $body1 .= '</p>'; $body1 .= '</body></html>'; $fromname = 'info@domain.com'; $fromemail = "info@domain.com"; $headers1 = "From: $fromname <$fromemail>\r\n"; $headers1 .= "Reply-To: $fromname <$fromemail>\r\n"; $headers1 .= "Return-Path: $fromname <$fromemail>\r\n"; $headers1 .= "MIME-Version: 1.0\r\n"; $headers1 .= "Content-type: text/html; charset=iso-8859-1\r\n"; // 5 $headers1 .= "X-Priority: 3\r\n"; $headers1 .= "X-MSMail-Priority: Normal\r\n"; $headers1 .= "X-Mailer: php\r\n"; ini_set("sendmail_from", "info@domain.com"); mail($to1, $subject1, $body1, $headers1, "-f".$fromemail); In one example, if only $_POST['file3'] existed, the contents of it would appear correct in the email, however if file1, file 2 and file3 exsted, file 3 would be corrupt and include an unwanted space and exclamation mark. Has anyone ever experienced this? Could it be down to charset? I'm not sure which charset I should be using for my php/html documents. Quote Link to comment https://forums.phpfreaks.com/topic/85808-emails-sent-via-mail-are-received-with-unwanted-spaces-and-exclamation-marks/#findComment-437934 Share on other sites More sharing options...
monkeytooth Posted January 13, 2008 Share Posted January 13, 2008 Thats got me stumpped.. Ive had my share of issues with mail() but never like that.. Maybe its im to sleepy to figure it out right now I dunno but to me that looks like there shouldnt be a problem.. Quote Link to comment https://forums.phpfreaks.com/topic/85808-emails-sent-via-mail-are-received-with-unwanted-spaces-and-exclamation-marks/#findComment-437941 Share on other sites More sharing options...
Edward Posted January 13, 2008 Author Share Posted January 13, 2008 I've just tried it again sing this as the content of the email: $additional_email_content .= '<tr><td width="10" align="left" valign="top" cellpadding="0" cellspacing="0" border="0"></td><td width="120" height="170" align="center" valign="middle" cellpadding="0" cellspacing="0" border="0"><img src="http://www.mydomain.co.uk/page_02_search_actors/scotland/stephen_mcdonald_small.jpg" width="120" height="160" alt="" border="0" /></td><td width="10" align="left" valign="top" cellpadding="0" cellspacing="0" border="0"></td><td width="650" align="left" valign="top" cellpadding="0" cellspacing="0" border="0"><p>Stephen McDonald<br />Glasgow</p></td><td width="10" align="left" valign="top" cellpadding="0" cellspacing="0" border="0"></td></tr>'; When I test it locally, the email I receive changes 'Stephen McDonald' to 'Steph en McDonald' (tested twice in a row). When I test it on the website, the email I receive changes 'Stephen McDonald' to 'Step! hen McDonald'. How can an error be so random? Quote Link to comment https://forums.phpfreaks.com/topic/85808-emails-sent-via-mail-are-received-with-unwanted-spaces-and-exclamation-marks/#findComment-437949 Share on other sites More sharing options...
monkeytooth Posted January 13, 2008 Share Posted January 13, 2008 your hosting provider isnt using something like magic quotes is it? Quote Link to comment https://forums.phpfreaks.com/topic/85808-emails-sent-via-mail-are-received-with-unwanted-spaces-and-exclamation-marks/#findComment-437951 Share on other sites More sharing options...
Edward Posted January 18, 2008 Author Share Posted January 18, 2008 I found the problem...eventually...at http://uk3.php.net/mail - see the post at 26-May-2005 10:18. Here is the post and the solution: "If you are seeing unwanted line breaks preceded by exclamation marks ("!") in the emails you send with mail(), you may be having the same problem I had: exceeding the maximum line length (998 chars) specified in RFC 2822 (http://www.faqs.org/rfcs/rfc2822.html). You can get around this restriction by using base64 encoding: add a "Content-Transfer-Encoding: base64" header and encode the contents with $base64contents = rtrim(chunk_split( base64_encode($contents)));" Does anyone know an ALTERNATIVE way around this? As using base64_encode() converts the message to what looks like a random string of random letters and numbers. Although the email looks fine when received, some servers spam filter stops the email from sendign, as it looks like spam. Any help would be great, perhaps line breaks can be inserted to resolve the problem? I'm not sure how these work, somethign like \r\n? Quote Link to comment https://forums.phpfreaks.com/topic/85808-emails-sent-via-mail-are-received-with-unwanted-spaces-and-exclamation-marks/#findComment-442582 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.