Reputation: 1009
The Content type is handle as a part of message , how to fix that ? thanks
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: <flippingST@DPS_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: flippingST@DPS_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: <20130605042928.D8FEE4329E@DPS_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
The above is the mail source code, notice the
Content type ,From: [email protected] <[email protected]>
Message-Id: <20130605042928.D8FEE4329E@DPS_FDBD.localdomain>
Date: Wed, 5 Jun 2013 00:29:28 -0400 (EDT)
is part of mail message
Here is the php code, I have set the Content type as header , but it seems it cut off after MIME version 1.0 ? How to fix this? thanks.
<?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';
}
?>
Upvotes: 0
Views: 340
Reputation: 2180
If you use the PHP_EOL constant, then you don't need to worry about \r or \n or \r\n, and your code would be more portable across servers.
Upvotes: 0
Reputation: 1009
Using \r
instead of \r\n
fixed the problem.
Possibly due to server settings.
Upvotes: 2
Reputation: 9142
Put your FROM header above the MIME-Version and Content-type definition.. Just swap 'em:
// 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";
Upvotes: 1