php
  • email
  • encoding
  • hotmail
  • 2011-08-25 17 views 3 likes 
    3

    我正在使用以下代碼向我的站點的成員發送電子郵件。該腳本起作用並且電子郵件由用戶接收。但是,在發送電子郵件到Hotmail或Notes時遇到編碼問題。使用PHP向Hotmail發送電子郵件時的編碼問題

    的代碼:

    $to  = "[email protected]"; 
    $headers = 'MIME-Version: 1.0' . "\r\n"; 
    $headers .= 'Content-type: text/plain; charset="utf-8"; format="flowed"' . "\r\n"; 
    $headers .= 'Content-Transfer-Encoding: 8bit'. "\n\r\n"; 
    $headers .= "To: John Doe<[email protected]>" . "\r\n" . 
    "From: John Smith<[email protected]" . "\r\n" . 
    "Reply-To: [email protected]" . "\r\n" . 
    "Return-Path: [email protected]" . "\r\n" . 
    "Sender: [email protected]" . "\r\n" . 
    "X-Sender: [email protected]" . "\r\n" . 
    "X-Mailer: JohnDoe". "\r\n". 
    "X-Report-Abuse: Please report abuse to: [email protected]"; 
    
    //If the e-mail was successfully sent... 
    $subject = $translation[104]; 
    if(mail($to, $subject, $message, $headers)){ 
    
    } 
    

    兩個消息和主題包含瑞典字母A,A型和O。實際的消息被正確編碼並在Hotmail中查看,而主題不是。您可以查看下面的圖片瞭解更多信息:

    圖片:http://www.aspkoll.se/imgo/649

    我很困惑。我已經搜索了好幾天,嘗試了不同的解決方案,但是我害怕沒有取得任何成功。

    你能幫我解決這個問題嗎?

    讚賞!

    +1

    可能重複[如何發送郵件主題使用PHP中的二進制字](http://stackoverflow.com/questions/1450846/how-to-send-mail-with-binary-word-in-mail-subject-using-php) –

    +0

    你不能郵件標題中包含非ASCII字符。這違反了規則。 – tchrist

    回答

    6

    電子郵件主題和其他頭內容,如名稱,在使用上mail()RFC 2047

    php.net意見給予了下面的例子編碼:

    mail($mail, "=?utf-8?B?".base64_encode ($subject)."?=", $message, $headers); 
    
    +0

    謝謝。這幫了我很多! – Shubbi

    -1

    嘗試http://www.phpclasses.org/browse/file/919.html。它適用於Yahoo郵件,Gmail,Hotmail。

    P.S .: Hotmail糟透了。 :)

    相關問題