Daniel
Daniel

Reputation: 33

Extra character appearing in email subject £ in front of pound symbol

I am using a class system php file to send an HTML email from mysql database, an extra character appears in front of the £pound symbol in the subject title, but the main content of the email is fine.

I have tried using a UTF charset for the email, but this breaks the actual email content area so all emails no longer send HTML content, although it does fix the subject £pound symbol problem. Also tried str_replace If there is a way to code it so the title only uses UTF and content HTML that would be perfect solution.

The email subject code sections are below (private details omitted)

function
sendTemplateEmail($groupid,$subject,$body,$tipster_code,
$email_image,$tipster_name,$only_active="",


{
        global $conn;

    $errors = "";
    $email_list = array();
    $total_users = 0;
    $group = (is_numeric($groupid)) ? $groupid : 0;

    #die("body = ".$body);

    $body = str_replace("£","£",$body);
    $body = str_replace("Â","",$body);
    $subject = str_replace("Â","",$subject);


 $html = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
 $html .= "<html lang='en'>\n";
 $html .= "<head>\n";
 $html .= "<meta http-equiv=\"Content-Type\" content=\"text/html;   charset=iso-8859-1\">\n";
 $html .= "<title>O.com</title>\n";
 $html .= "</head>\n";
 $html .= "<body style='width:800px;' bgcolor=\"#FFFFFF\">\n";

$dw_mail->AddReplyTo("admin@","");
$dw_mail->ReturnPath = "admin@";
$dw_mail->From = $from;
$dw_mail->FromName = $from;
$dw_mail->AddAddress($users['email'],"");
$dw_mail->AddAddress("@hotmail.com","");
$dw_mail->WordWrap = 50;                              // set word wrap
//$dw_mail->AddAttachment(PDF_PATH."app-".$app.".pdf");
$dw_mail->IsHTML(); // send as html
$dw_mail->Subject  =  stripslashes($subject);
$dw_mail->Body = $html;
$dw_mail->AltBody = stripslashes($alt_body);

Upvotes: 2

Views: 1513

Answers (1)

Antoine Mottier
Antoine Mottier

Reputation: 1183

In UTF-8 £ character is encoded on two bytes: C2 A3 C2 A3 decoded using ISO-8859-1 gives: £

So I guess that the value of the subject that you get from MySQL database is encoded in UTF-8 whereas $dw_mail->Subject expect a value encoded in ISO-8859-1.

Using mb-convert-encoding should let you do the conversion from UTF-8 to ISO-8859-1. Note that not all UTF-8 characters can be mapped to ISO-8859-1 so you might have issue with other special characters.

Upvotes: 3

Related Questions