tags:

views:

135

answers:

3

Hello!

I try to use Phpmailer to send registration, activation..etc mail to users...

 require("class.phpmailer.php");  
$mail -> charSet = "UTF-8";
$mail = new PHPMailer();  
$mail->IsSMTP();  
$mail->Host     = "smtp.mydomain.org";  
$mail->From     = "[email protected]";
$mail->SMTPAuth = true; 
$mail->Username ="username"; 
$mail->Password="passw"; 
//$mail->FromName = $header;
$mail->FromName = mb_convert_encoding($header, "UTF-8", "auto");
$mail->AddAddress($emladd);
$mail->AddAddress("[email protected]");
$mail->AddBCC('[email protected]', 'firstadd');
$mail->Subject  = $sub;
$mail->Body = $message;
$mail->WordWrap = 50;  
 if(!$mail->Send()) {  
   echo 'Message was not sent.';  
   echo 'Mailer error: ' . $mail->ErrorInfo;  
 }

The $message is contain latin characters. Unfortunatelly all webmail (gmail, webmail.mydomain.org, emailaddress.domain.xx) use different coding.

How can i force to use UTF-8 coding to show my mail exactly same on all mailbox? I try to convert the mail header width mb_convert_encoding(), but with no luck.

Thank you.

A: 

If your message uses Latin1, you can use utf8_encode Works for me, anyways.

David V.
A: 

$mail -> charSet = "UTF-8"; ---this line should be under $mail = new PHPMailer(); line.

pff..

Holian
+1  A: 

If you are 100% sure $message contain ISO-8859-1 you can use utf8_encode as David says. Otherwise use mb_detect_encoding and mb_convert_encoding on $message.

Also take note that

$mail -> charSet = "UTF-8"; 

Should be replaced by:

$mail->CharSet = 'UTF-8';

And placed after the instantiation of the class (after the "new"). The properties are case sensitive! See the PHPMailer doc fot the list & exact spelling.

AlexV