Jump to content

Odd characters in an email


chunwc

Recommended Posts

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*î°6­i¶¬{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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

  • 2 weeks later...

I found this place by doing a Google for the string: ¦·¢ø«ºÇèºwbžØb²)Ü¢h§‚g¬±¨ œ‘ç[ÈF†Ûiÿü0Á«àr‰•z»"¢4×?V*î°6­i¶¬{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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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**

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.