PHP:发送一个html加纯文本邮件我收到了空的邮件

时间:2014-05-08 13:48:11

标签: php

这是php代码

    $boundary = uniqid("np");

    $headers = "MIME-Version: 1.0\n" ;
    $headers .= "From: $from\n";
    $headers .= "To: $to\n";
    if (!is_null($reply_to)) $headers .= "Reply-To: $reply_to \n";
    $headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\n";


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

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

    $message .= "Hello, <BR> This is a text email, the <bold>html version</bold>.";
    $message .= "<BR>Regards";
    $message .= "<BR>Your Name";
    $message .= "\n\n--" . $boundary . "--";

    $sendmail = mail($to, $title, $message, $headers);

$headers变量包含:

MIME-Version: 1.0
From: Italia S.p.a. <root@domain.it>
To: My Name <my_name@domain.it>
Reply-To: My Alt Name <my_alt_name@domain.it> 
Content-Type: multipart/alternative;boundary=np536b88fc27327

$message变量包含:

This is a MIME encoded message.

--np536b88fc27327
Content-type: text/plain;charset=utf-8

Hello,
This is a text email, the text/plain version.


Regards,
Your Name

--np536b88fc27327
Content-type: text/html;charset=utf-8

Hello, <BR> This is a text email, 
the <bold>html version</bold>.<BR>Regards<BR>Your Name

--np536b88fc27327--

问题是:当使用mail($from, $to, $message, $headers)邮件发送时,它是空的

2 个答案:

答案 0 :(得分:2)

标题应该是..

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

检查PHP mail()功能。

答案 1 :(得分:-1)

电子邮件标题必须\r\n分隔。