chunwc Posted July 22, 2008 Share Posted July 22, 2008 Hi. I'm a relative novice with php but have been using this script for a mail function. I do edit the file from time to time so it's probably user-induced error, but I can't see for the life of me where the problem is, so if some kind soul may be able to offer some advice for where to look. Anyway, the problem is that I'm getting really random letters appearing at the end of the email that gets sent out. Today, I had: ¦·¢ø«ºÇèºwbžØb²)Ü¢h§‚g¬±¨ œ‘ç[ÈF†Ûiÿü0Á«àr‰•z»"¢4×?V*î°6i¶¬{nôçõç®QzWš±àÚµíµÿNÿÛM<×ÍúþšÞ In the email it appears directly after 'Kind regards, COMPANYNAME'. (I'm not sure if the characters will come out in this forum.) Here is the (slightly edited) code: ***start of code in main body $pforename=trim($_POST['forename']); //ie. a user has filled in this first name $psurname=trim($_POST['surname']); //ie. a user has filled in a surname $pemail=trim($_POST['email1']); //ie. a user has filled in their email address $mail = new mime_mail(); $mail->from = "*a business email address*"; $mail->headers = "Bcc: *the same address as above*"; $mail->to = $pemail; $mail->subject = "User registration"; $mail->body = "<html><body>Dear ".$pforename." ".$psurname.",<br /><br />Thank you for taking an interest in COMPANYNAME and registering with us. This e-mail is a courtesy to confirm your registration. If you did not register, please reply to this e-mail and let us know.<br /><br />If you have any questions regarding COMPANYNAME, please contact us at your convenience.<br /><br />Kind regards,<br />COMPANYNAME</body></html>"; $mail->send(); ***end of code I use Thunderbird as my e-mail client. I'm sure when I first wrote this and tested it the random characters weren't there (I have some old test emails to prove it) but cannot see what I've done to introduce the errors. Any help greatly appreciated. ***php code for the mail class (which can send attachments) class mime_mail { var $parts; var $to; var $from; var $headers; var $subject; var $body; function mime_mail() { $this->parts = array(); $this->to = ""; $this->from = ""; $this->subject = ""; $this->body = ""; $this->headers = ""; } function add_attachment($message, $name = "", $ctype = "application/octet-stream") { $this->parts[] = array ( "ctype" => $ctype, "message" => $message, "encode" => $encode, "name" => $name ); } function build_message($part) { $message = $part["message"]; $message = chunk_split(base64_encode($message)); $encoding = "base64"; if ($part["name"]!="") { $dispstring = "Content-Disposition: attachment; filename=\"$part[name]\"\n"; } return "Content-Type: ".$part["ctype"]. ($part["name"]?"; name = \"".$part["name"]."\"" : ""). "\nContent-Transfer-Encoding: $encoding\n".$dispstring."\n$message\n"; } function build_multipart() { $boundary = "b".md5(uniqid(time())); $multipart = "Content-Type: multipart/mixed; boundary=$boundary\n\nThis is a MIME encoded message.\n\n--$boundary"; for($i = sizeof($this->parts)-1; $i >= 0; $i--) { $multipart .= "\n".$this->build_message($this->parts[$i])."--$boundary"; } return $multipart.= "--\n"; } function send() { $mime = ""; if (!empty($this->from)) $mime .= "From: ".$this->from."\n"; if (!empty($this->headers)) $mime .= $this->headers."\n"; if (!empty($this->body)) $this->add_attachment($this->body, "", "text/html");//text/plain $mime .= "MIME-Version: 1.0\n".$this->build_multipart(); $success = mail($this->to, $this->subject, "", $mime); if (!$success) { echo 'Mail: Warning, mail could not be sent'; } else { //echo 'Thank you for registering. Please check your e-mail to finalise the registration procedure.'; } } } ***end of code Quote Link to comment https://forums.phpfreaks.com/topic/116009-odd-characters-in-an-email/ Share on other sites More sharing options...
MadTechie Posted July 22, 2008 Share Posted July 22, 2008 first try removing Kind regards, COMPANYNAME</body> and then add </body> and test (pleasse remove the </body> and then re-type it, you may have copied and pasted some extended chars, also change $mail->headers = "Bcc: *the same address as above*"; to $mail->headers = "Bcc: *the same address as above*\r\n"; $mail->headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; EDIT: you could also try UTF-8 instead of iso-8859-1 Quote Link to comment https://forums.phpfreaks.com/topic/116009-odd-characters-in-an-email/#findComment-596485 Share on other sites More sharing options...
chunwc Posted July 22, 2008 Author Share Posted July 22, 2008 Thanks for the reply. first try removing Kind regards, COMPANYNAME</body> and then add </body> and test (pleasse remove the </body> and then re-type it, you may have copied and pasted some extended chars, Yes, I tried this and it was no different. also change $mail->headers = "Bcc: *the same address as above*"; to $mail->headers = "Bcc: *the same address as above*\r\n"; $mail->headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; EDIT: you could also try UTF-8 instead of iso-8859-1 I tried all of these options and now the emails look like this: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=ba8828dd489dcd87951cdb3a89fa5383d This is a MIME encoded message. --ba8828dd489dcd87951cdb3a89fa5383d Content-Type: text/html Content-Transfer-Encoding: base64 PGh0bWw+PGJvZHk+RGVhciBUaGlyZCBUZXN0LDxiciAvPjxiciAvPlRoYW5rIHlvdSBmb3IgdGFr aW5nIGFuIGludGVyZXN0IGluIEJpbzJCdXNpbmVzcyBhbmQgcmVnaXN0ZXJpbmcgd2l0aCB1cy4g VGhpcyBlLW1haWwgaXMgYSBjb3VydGVzeSB0byBjb25maXJtIHlvdXIgcmVnaXN0cmF0aW9uLiBJ ZiB5b3UgZGlkIG5vdCByZWdpc3RlciwgcGxlYXNlIHJlcGx5IHRvIHRoaXMgZS1tYWlsIGFuZCBs ZXQgdXMga25vdy48YnIgLz48YnIgLz5JZiB5b3UgaGF2ZSBhbnkgcXVlc3Rpb25zIHJlZ2FyZGlu ZyBCaW8yQnVzaW5lc3MsIHBsZWFzZSBjb250YWN0IHVzIGF0IHlvdXIgY29udmVuaWVuY2UuPGJy IC8+PGJyIC8+S2luZCByZWdhcmRzLDxiciAvPkJpbzJCdXNpbmVzczwvYm9keT48L2h0bWw+ --ba8828dd489dcd87951cdb3a89fa5383d-- However, I am beginning to think that it is something to do with Thunderbird (I vaguely recall an update happening to it recently), as I cc'd myself to a Yahoo account and there was none of the extra text there, so I apologise if I've wasted your time. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/116009-odd-characters-in-an-email/#findComment-596557 Share on other sites More sharing options...
MadTechie Posted July 22, 2008 Share Posted July 22, 2008 What your seeing is normally unseen (unless you turn the options on) in the email but it likely valid, try this $mail->headers = "MIME-Version: 1.0\r\n"; //Add this $mail->headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $mail->headers .= "Bcc: *the same address as above*\r\n"; //move this down one Quote Link to comment https://forums.phpfreaks.com/topic/116009-odd-characters-in-an-email/#findComment-596668 Share on other sites More sharing options...
chunwc Posted July 23, 2008 Author Share Posted July 23, 2008 Thanks again for taking a look at this but I'm afraid it didn't make any difference - the Mime information was also in the mime_mail class too, so I guess duplicating it wouldn't have helped? (I get an unreadable MIME encoded message in both Yahoo and Thunderbird.) I also changed the '\n\n' that were in the mime_mail class to '\r\n' - then my original problem resurfaced. I've tried to find out more information about Thunderbird but navigating the site there hasn't helped me any further. So, my final code looked like this: $mail = new mime_mail(); $mail->from = "*my email*"; $mail->headers = "MIME-Version: 1.0\r\n"; $mail->headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $mail->headers .= "Bcc: *my email*\r\n"; $mail->to = $pemail; Quote Link to comment https://forums.phpfreaks.com/topic/116009-odd-characters-in-an-email/#findComment-597352 Share on other sites More sharing options...
jtb Posted August 6, 2008 Share Posted August 6, 2008 I found this place by doing a Google for the string: ¦·¢ø«ºÇèºwbžØb²)Ü¢h§‚g¬±¨ œ‘ç[ÈF†Ûiÿü0Á«àr‰•z»"¢4×?V*î°6i¶¬{nôç]¿×ŸyEé^jǃj×¼ÿ¯öÓO<Ûp þšÞ If I'm following this right you think some code entered by the OP caused this problem. I have that string appearing at the end of email from a computer that has not had code added. Our computer is a Dell, using Outlook Express, AVG Antivirus. The strange looking string is inserted at the end of email and before the AVG checked posts. I have looked for a signature line, nothing there. I have even turned AVG off and the line is still there. Ran AdAware, complete AVG Free scan, emptied cookies/history and cache. Rebooted computer. Nothing resets to stop the string. Have tried to translate the string without success. I have several other computers setup similar and they don't have the string in their email. Any suggestions? Jim I modify this to say that sending blank email, with AVG off, will send the string and not the blank email intended. I had thought it was a AVG problem but that doesn't seem to be the case. Quote Link to comment https://forums.phpfreaks.com/topic/116009-odd-characters-in-an-email/#findComment-609956 Share on other sites More sharing options...
jtb Posted August 6, 2008 Share Posted August 6, 2008 I did go into Outlook Express, made a signature of "Thank You" and sent myself a email on another computer. The string was shortened to " ¦¢ººž²¢‚± ‘ȆÿÁrz¢×V°i{ç×EjjÿÓÛþ ". Also checked the saved email on the original computer and the strings don't show there. Only on the recieving machines. Quote Link to comment https://forums.phpfreaks.com/topic/116009-odd-characters-in-an-email/#findComment-609966 Share on other sites More sharing options...
jtb Posted August 6, 2008 Share Posted August 6, 2008 Have found out that the person replying to emaiil with the string get a popup asking how they want to reply to the email. It says "send as Unicode", "send as is" or "cancel". Where is a setting for Unicode to be turned off in Outlook Express? Quote Link to comment https://forums.phpfreaks.com/topic/116009-odd-characters-in-an-email/#findComment-610024 Share on other sites More sharing options...
jtb Posted August 6, 2008 Share Posted August 6, 2008 Went to Embarq, my ISP. They don't know anything, as usual, but suggest I remove and reinstall Outlook Express. Not bloody likely. Quote Link to comment https://forums.phpfreaks.com/topic/116009-odd-characters-in-an-email/#findComment-610072 Share on other sites More sharing options...
chunwc Posted August 7, 2008 Author Share Posted August 7, 2008 Just as an update, I'm still getting the odd code in Thuderbird, so I guess it's not a Thunderbird issue. However, I do use AVG as well (version 8.0.138) However, it doesn't seem to have any negative effects so I haven't spent any more time trying to fix it. Quote Link to comment https://forums.phpfreaks.com/topic/116009-odd-characters-in-an-email/#findComment-610489 Share on other sites More sharing options...
MadTechie Posted August 7, 2008 Share Posted August 7, 2008 As your only doing html and not using attachments, try this trimmed and cleaned up rewrite, if this is okay then i can add a extra routine to add attachments <?php class mime_mail { var $parts; var $to; var $from; var $headers; var $subject; var $body; function mime_mail() { $this->parts = array(); $this->to = ""; $this->from = ""; $this->subject = ""; $this->body = ""; $this->headers = ""; } function send() { $mime = "MIME-Version: 1.0\r\n"; $mime .= "Content-type: text/html; charset=iso-8859-1\r\n"; if (!empty($this->to)) $mime .= "To: ".$this->to."\r\n"; if (!empty($this->from)) $mime .= "From: ".$this->from."\r\n"; if (!empty($this->headers)) $mime .= $this->headers."\r\n"; $success = mail($this->to, $this->subject, $this->body, $mime); if (!$success) { echo 'Mail: Warning, mail could not be sent'; }else{ //echo 'Thank you for registering. Please check your e-mail to finalise the registration procedure.'; } } } ?> **UNTESTED** Quote Link to comment https://forums.phpfreaks.com/topic/116009-odd-characters-in-an-email/#findComment-610566 Share on other sites More sharing options...
chunwc Posted August 19, 2008 Author Share Posted August 19, 2008 Sorry for the late reply, but got a chance to try the code and it worked great! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/116009-odd-characters-in-an-email/#findComment-620554 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.