php:message缺少纯文本替换部分

时间:2015-11-17 11:11:51

标签: php

SpamAssasin对我的电子邮件有所了解:“消息缺少纯文本替代部分”

这是我使用的php函数:

 function sendEmail($to, $subject, $message, $from) {

    $headers = "From: $from \r\n" .
    "Reply-To: $from \r\n".
    "MIME-Version: 1.0 \r\n".
    "Content-type: text/html; charset=utf-8 \r\n";       
    @mail($to, $subject ,$message, $headers); 
 } 

如何添加替代纯文本?

1 个答案:

答案 0 :(得分:1)

尽管你应该使用smtp来发送邮件,但这就是你想要的

//specify the email address you are sending to, and the email subject
$email = 'email@example.com';
$subject = 'Email Subject';

//create a boundary for the email. This 
$boundary = uniqid('np');

//headers - specify your from email address and name here
//and specify the boundary for the email
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: Your Name \r\n";
$headers .= "To: ".$email."\r\n";
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";

//here is the content body
$message = "This is a MIME encoded message.";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/plain;charset=utf-8\r\n\r\n";

//Plain text body
$message .= "Hello,\nThis is a text email, the text/plain version.
\n\nRegards,\nYour Name";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/html;charset=utf-8\r\n\r\n";

//Html body
$message .= "
 Hello,
This is a text email, the html version.

Regards,
Your Name";
$message .= "\r\n\r\n--" . $boundary . "--";

//invoke the PHP mail function
mail('', $subject, $message, $headers);

Source: kevinjmcmahon.net

是的,抱歉忘了