0

我正在使用我以前使用过的非常标准的电子邮件创建功能,但由于某种我无法弄清楚的原因它不起作用。无论我在其中放入什么内容,它都会发送一封空白电子邮件。

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");

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

4

1 回答 1

0

--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);
}
于 2012-08-21T19:05:48.227 回答