php
  • email
  • mime
  • 2014-02-16 18 views 0 likes 
    0

    我有一些問題,我的PHP郵件程序,我只收到源代碼不interprated。PHP MIME頭

    有人可以檢查我的標題?

    $recipient = str_replace(Array("\r","\n"),"",$this->to); 
    $headers = 'From: "xxx.ch" <[email protected]> '."\r\n"; 
    $headers .= 'Return-Path: <[email protected]>' . "\r\n"; 
    if (isset($this->replyTo)){ 
        $headers .= 'Reply-To: [email protected]' . "\r\n"; 
    } 
    $random_hash = md5(date('r', time())); 
    $headers .= "MIME-Version: 1.0 \r\n Content-Type: multipart/alternative; boundary=\"".$random_hash."\""; 
    $body = '--'.$random_hash."\r".' 
         Content-Type: text/plain; charset="UTF-8"'."\r".' 
         Content-Transfer-Encoding: 8bit'."\r".' 
    
         Merci d\'utiliser un client mail supportant le format HTML'."\r".' 
    
         --'.$random_hash."\r".' 
    
         Content-Type: text/html; charset="UTF-8"'."\r".' 
         Content-Transfer-Encoding: 8bit'."\r"; 
    $body .= $this->HTMLBody ."\r".'--'.$random_hash.'--'; 
    

    感謝

    +0

    您的服務器設置爲發送電子郵件嗎?什麼SMTP服務正在運行? PHP配置是否正確發送電子郵件? –

    +0

    是服務器配置是好的,但對於一些舊的郵件客戶端不支持HTML,所以我必須添加對它們的支持,現在用MIME我有很多的錯誤:-( –

    +0

    你有沒有看過使用PEAR的MIME郵件包 – miken32

    回答

    1

    雖然我與其他評論者,你應該看看一個第三方庫,而不是做手工同意這種說法,你目前的問題是可能與行結束和空白做, MIME非常挑剔。

    您現在有很多這樣的代碼:

    $body = '--'.$random_hash."\r".' 
         Content-Type: text/plain; charset="UTF-8"'."\r".' 
         Content-Transfer-Encoding: 8bit'."\r"; // (and so on) 
    

    您正在小心插入一個回車("\r"),但是嵌入換行符和大量空白的進入下一個單引號的字符串爲好。

    相反,你應該包括回車,並確保所有其他的空格是單引號之外(你想要的PHP是可讀的,但對於不影響輸出):

    $body = '--' . $random_hash . "\r" 
         . 'Content-Type: text/plain; charset="UTF-8"'."\r" 
         . 'Content-Transfer-Encoding: 8bit'."\r"; // (and so on) 
    
    +0

    工作很好,謝謝 –

    相關問題