1

我必须使用 PHP 的函数 mail() 发送邮件。我必须插入回复标题,但它不起作用:

<?php
    $body = "<html>\n";
    $body .= "<body style=\"font-family:Verdana, Verdana, Geneva, sans-serif; font-size:12px; color:#666666;\">\n";
    $body = $message;
    $body .= "</body>\n";
    $body .= "</html>\n";

    $headers  = "From: My site<noreply@example.com>\r\n";
    $headers .= "Reply-To: info@example.com\r\n";
    $headers .= "Return-Path: info@example.com\r\n";
    $headers .= "X-Mailer: Drupal\n";
    $headers .= 'MIME-Version: 1.0' . "\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    return mail($recipient, $subject, $message, $headers); ?>

在这个 php.net 的例子中有 $headers .= "Reply-To: info@example.com\r\n"; 但是如果复制并粘贴这个然后发送邮件,则没有回复标题。如果在我的 HTML 邮件中正确插入 From、CC、Bcc 等其他标头,则只有回复标头没有。我尝试过“回复”、“回复”、“回复”、“回复”等,但它不起作用。我已经用过 Php 5.4 能帮帮我吗?

4

1 回答 1

3

尝试这个。

为收件人、主题和消息添加参数。

然后在这一行“return mail($recipient, $subject, $message, $headers);”

将 $message 替换为 $body。

看起来像这样

<?php

$recipient = "jack@example.com";
$subject = "test subject";
$message = "test message";
$body = "<html>\n";
$body .= "<body style=\"font-family:Verdana, Verdana, Geneva, sans-serif; font-size:12px; color:#666666;\">\n";
$body = $message;
$body .= "</body>\n";
$body .= "</html>\n";

$headers  = "From: My site<noreply@example.com>\r\n";
$headers .= "Reply-To: info@example.com\r\n";
$headers .= "Return-Path: info@example.com\r\n";
$headers .= "X-Mailer: Drupal\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$result = mail($recipient, $subject, $body, $headers); 
var_dump($result);

?>

希望对你有帮助

于 2012-07-23T10:40:33.883 回答