電子郵件主題中出現的額外字符 £ 在英鎊符號前面 (Extra character appearing in email subject £ in front of pound symbol)


問題描述

電子郵件主題中出現的額外字符 £ 在英鎊符號前面 (Extra character appearing in email subject £ in front of pound symbol)

我正在使用類系統php文件從mysql數據庫發送HTML電子郵件,主題標題中的英鎊符號前面出現了一個額外的字符,但電子郵件的主要內容很好。

我曾嘗試為電子郵件使用 UTF 字符集,但這會破壞實際的電子郵件內容區域,因此所有電子郵件都不再發送 HTML 內容,儘管它確實解決了主題英鎊符號問題。還嘗試了 str_replace 如果有辦法對其進行編碼,因此標題僅使用 UTF 和內容 HTML,這將是完美的解決方案。

電子郵件主題代碼部分如下(省略私人細節)

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);

參考解法

方法 1:

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.

(by DanielAntoine Mottier)

參考文件

  1. Extra character appearing in email subject £ in front of pound symbol (CC BY‑SA 2.5/3.0/4.0)

#PHP #utf






相關問題

無法連接 - 數據庫或編碼錯誤 (Could Not Connect - Database or Coding Error)

Laravel Put Route Giving 404 錯誤 (Laravel Put Route Giving 404 Error)

從數據庫導入的鏈接以 UTF8 截斷 (imported link from database cut off at UTF8)

如何使用tinymce在數據庫中插入數據 (how to insert data in database using tinymce)

Tối ưu hóa truy vấn MySQL PHP - Phản hồi (MySQL PHP Query Optimization - Feedbacks)

為什麼是這種類型的數組? (Why type of array is this?)

php唯一隨機數數組有異常 (php unique randomized numbers array with exception)

使用雙引號格式並用逗號分隔元素數組 (Implode an element array with double quote format and separated by comma)

顯示數組中的類別和子類別 (Display categories and subcategories from an array)

AJAX/PHP/JS - 無法將頁面內容加載到容器中 (AJAX/PHP/JS - Cannot load page content into container)

將字符串轉換為類的安全名稱 (Convert string to safe name for class)

代幣支付 Laravel (Coinpayment Laravel)







留言討論