2013-06-05 41 views
0

內容類型作爲消息的一部分進行處理,如何解決該問題?感謝無法在PHP中設置郵件標題

From - Wed Jun 05 12:29:59 2013 
X-Account-Key: account1 
X-UIDL: 50933ddb0000053d 
X-Mozilla-Status: 0001 
X-Mozilla-Status2: 00000000 
X-Mozilla-Keys:                     
Return-Path: <[email protected]_FDBD.localdomain> 
Received: from xxxxxxxxx (SMTP1 [xxxxxxx]) 
    by xxxxxx (8.13.8/8.13.8) with ESMTP id r554TvMv018216 
    for <[email protected]>; Wed, 5 Jun 2013 12:29:57 +0800 
Received: from cip.singtaonewscorp.com (cip.singtaonewscorp.com [202.66.86.162] (may be forged)) 
    by xxxxxxx with Microsoft SMTPSVC(xxxxxxxxx); 
    for <[email protected]>; Wed, 5 Jun 2013 12:29:56 +0800 
Date: Wed, 5 Jun 2013 12:29:56 +0800 
From: [email protected]_FDBD.localdomain 
Message-Id: <[email protected]> 
X-IronPort-Anti-Spam-Filtered: true 
X-IronPort-Anti-Spam-Result: AogdALq9rlEuic+b/2dsb2JhbABagzk0gkEBhw+jHgsBkhIdTBd0giMBFQE7AQo8FQEBVgcNEySIEQiPSYxDjgYBAYVBAZxtgj6BBwMEC50ji02DSw 
X-IronPort-AV: E=Sophos;i="4.87,804,1363104000"; 
    d="scan'208,217";a="25969537" 
Received: from ec2-46-137-207-155.ap-southeast-1.compute.amazonaws.com (HELO DPS_FDBD.localdomain) ([46.137.207.155]) 
    by cip.singtaonewscorp.com with ESMTP; 05 Jun 2013 12:30:48 +0800 
Received: by DPS_FDBD.localdomain (Postfix, from userid 500) 
    id D8FEE4329E; Wed, 5 Jun 2013 00:29:28 -0400 (EDT) 
To: [email protected] 
Subject: =?UTF-8?B?5oql56ug5YaF5a655YiG5Lqr?= 
X-PHP-Originating-Script: 500:mail.php 
MIME-Version: 1.0 
X-EsetId: 40C9373366470C695FCF37616E1C4038 

Content-type: text/html; charset=UTF-8 

From: [email protected] <[email protected]> 
Message-Id: <[email protected]_FDBD.localdomain> 
Date: Wed, 5 Jun 2013 00:29:28 -0400 (EDT) 

<html><head></head><body><b>訊息 :</b>[email protected]</br></br>分享連結 :</b><a href = "http://46.137.207.155/?product=ChangSha&issue=20130524&page=1">按此觀看</a></br></br><img src = "https://s3-ap-southeast-1.amazonaws.com/demosource/ChangSha/2013/05/24/0/0/A/Content/1/Pg001.png" /></body></html> 

__________ Information from ESET NOD32 Antivirus, version of virus signature database 8412 (20130604) __________ 

The message was checked by ESET NOD32 Antivirus. 

http://www.eset.com 

以上是郵件的源代碼,注意到

Content type ,From: [email protected] <[email protected]> 
Message-Id: <[email protected]_FDBD.localdomain> 
Date: Wed, 5 Jun 2013 00:29:28 -0400 (EDT) 

是郵件消息的一部分

這裏是PHP代碼,我已經將內容類型設置爲報頭,但它似乎在MIME版本1.0後切斷?如何解決這個問題?謝謝。

<?php 
function encodeMIMEString ($enc, $string) 
{ 
    return "=?$enc?B?".base64_encode($string)."?="; 
} 

if (isset($_POST["data"])){ 
    // Get posted data 
    $mailStr = $_POST["data"]; 
    $mailStr = str_replace ('&page','#page',$mailStr); 
    $mailStr = str_replace ('&issue','#issue',$mailStr); 
    $info = explode("&", $mailStr); 

    // To send HTML mail, the Content-type header must be set 
    $headers = "MIME-Version: 1.0\r\nContent-type: text/html; charset=UTF-8\r\n"; 
    $headers .= "From: $info[0] <$info[0]>"; 

    // Read XML to place the headings in mail content 
    $xml = simplexml_load_file('lang'.DIRECTORY_SEPARATOR.$info[4].'.xml') 
     or die("Error: Cannot create object"); 

    $subject = (string)$xml->mailTitle; 
    $mailMsgDes = (string)$xml->mailMsgDes; 
    $mailLink = (string)$xml->mailLink; 
    $mailLinkView = (string)$xml->mailLinkView; 

    $message = nl2br(htmlentities(trim($info[2]), ENT_QUOTES, "UTF-8")); 

    $url = str_replace ('#page','&page',$info[3]); 
    $url = str_replace ('#issue','&issue',$url); 

    $mailContent = '<html><head></head><body><b>'.$mailMsgDes.' :</b>'.$message.'</br></br>'.$mailLink.' :</b><a href = "'.$url.'">'.$mailLinkView.'</a></br>'; 

    if (isset($info[5])){ 
     $mailContent = $mailContent."</br><img src = \"$info[5]\" />"; 
    } 
    if (isset($info[6])){ 
     $mailContent = $mailContent."</br><img src = \"$info[6]\" />"; 
    } 

    $mailContent .= '</body></html>'; 

    if (mail($info[1], encodeMIMEString("UTF-8", $subject), $mailContent, $headers)) 
     echo 'Mail sent'; 
} 
?> 
+0

先停止使用電子郵件(),它的令人難以置信下供電,啓動期運用郵件庫 – 2013-06-05 04:42:52

+0

謝謝你的建議,我所以現在我傾向於不改變其他替代 – user1871516

回答

2

使用\r,而不是\r\n解決了這一問題。

可能由於服務器設置。

1

把你從報頭中的MIME-以上版本和內容類型定義..只是交換「時間:

// To send HTML mail, the Content-type header must be set 
$headers = "From: $info[0] <$info[0]>\r\n"; 
$headers .= "MIME-Version: 1.0\r\nContent-type: text/html; charset=UTF-8\r\n\r\n"; 
+0

現在MIME-版本正在建設一個演示頁:1.0 內容類型:text/html; charset = UTF-8是郵件內容的一部分 – user1871516

+0

奇怪......你可能只想設置'From:{$ info [0]}'並測試它。 –

0

如果您使用PHP_EOL常量,那麼您不必擔心\ r或\ n或\ r \ n,並且您的代碼在各服務器之間的可移植性更高。