PHP邮件没有';不能以HTML格式工作


PHP mailer doesn't work in HTML format

我使用了一个以前使用过的非常标准的电子邮件创建功能,但由于某种原因我无法理解,它不起作用。无论我在里面放了什么内容,它都会发送一封空白电子邮件

function sendToUser($email,$admin_email,$subject,$content){
    $to=$email;
    $random_hash = md5(date('r', time())); 
    $headers = "From: Site Name <$admin_email>";
    $headers .= "'r'nReply-To: $admin_email";
    $headers .= "'r'nContent-Type: multipart/alternative; boundary='"PHP-alt-".$random_hash."'""; 
    ob_start(); //Turn on output buffering
    ?>
    --PHP-alt-<?php echo $random_hash; ?> 
    Content-Type: text/plain; charset="utf-8"
    Content-Transfer-Encoding: 7bit
    <?php echo $content; ?>
    --PHP-alt-<?php echo $random_hash; ?>--
    <?
    //copy current buffer contents into $message variable and delete current output buffer
    $message = ob_get_clean();
    mail($to, $subject, $message, $headers);
}

现在,如果我这样称呼它:

sendToUser("myprivatemail@yahoo.com","admin@site.com","Testing","E-mail content");

它发送电子邮件,但收到的却是空的。有人看到这里出了什么问题吗?或者可能是我不熟悉的服务器设置?

--PHP-alt-<?php echo $random_hash;前面不能有空格。

试试这个:

function sendToUser($email,$admin_email,$subject,$content){
    $to=$email;
    $random_hash = md5(date('r', time())); 
    $headers = "From: Site Name <$admin_email>";
    $headers .= "'r'nReply-To: $admin_email";
    $headers .= "'r'nContent-Type: multipart/alternative; boundary='"PHP-alt-".$random_hash."'""; 
    ob_start(); //Turn on output buffering
    ?>
--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
<?php echo $content; ?>
--PHP-alt-<?php echo $random_hash; ?>--
    <?
    //copy current buffer contents into $message variable and delete current output buffer
    $message = ob_get_clean();
    mail($to, $subject, $message, $headers);
}