从Windows系统(本地)运行正常,但是在托管到centos中后,邮件以加密格式发送。我正在使用以下代码发送邮件。
$boundary = md5("sanwebe");
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From:".$from_email."\r\n";
$headers .= "Reply-To: ".$from_email."" . "\r\n";
$headers .= "CC: ".$cc."" . "\r\n";
$headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n";
$body = "--$boundary\r\n";
$body .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$body .= "Content-Transfer-Encoding: base64\r\n\r\n";
$body .= chunk_split(base64_encode($message));
//attachment
if (file_exists($file_name)){
$body .= "--$boundary\r\n";
$body .="Content-Type: $file_type; name=".$file_name."\r\n";
$body .="Content-Disposition: attachment; filename=".$file_name."\r\n";
$body .="Content-Transfer-Encoding: base64\r\n";
$body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n";
$body .= $encoded_content;
}
$sentMail = @mail($recipient_email, $subject, $body, $headers);
Ouput Mail是:
8de2a431c506316063ec3a4044192e46
PGh0bWw+PGJvZHk+PHN0cm9uZz5EZWFyIFNpci9NYWRhbSw8L3N0cm9uZz4gPGJyIC8+DQo8YnIg
Lz4NCgkJIEluc3RydW1lbnQgOiBHQy8wMiwgc2VyaWFsX251bWJlciA6IEMxMjA5NTMwMjQ2Nywg
bWFrZSA6U2hpbWFkenUgIG1vZGVsIDpHQyAyMDEwIFBsdXMtIEluc3RydW1lbnQgaXMgYnJlYWtk
b3duIFBsZWFzZSBhbGxvdCBzZXJ2aWNlIFBlcnNvbiA8YnIgLz4NCjxiciAvPg0KQmVzdCBSZWdh
cmRzPGJyIC8+DQpBZG1pbiw8YnIgLz4NCiAgQWRtaW4sPGJyIC8+DQpWaW10YSBMYWJzIExpbWl0
ZWQuPC9ib2R5PjwvaHRtbD4=