Mail()BCC - 无法让它工作

时间:2016-02-18 15:58:45

标签: php wordpress

我在创建一个向用户发送表单结果(一些计算)的邮件功能时遇到了一些麻烦。它工作正常,直到我添加了一个密件抄送标题,现在没有发送电子邮件。

相关代码如下,页面可以在这里看到: http://benefacto.org/calculator/

这是我的第一个主要的php项目!

这是我的邮件功能:

if($_POST["submit1"]) {
    $recipient=$_POST["email"] . ",example@example.org";
    $subject="Volunteering Costs at $companyname";
    $sender=$_POST["sender"];
    $senderEmail="example@example.org";
    $message=round($recturnoverdcrease,3) . "%";
    $message1=$_POST["companyname"];
    $message2=round($totalcost,2);
    $message3=round($increaserec,3) . "%";
    $themodel='http://benefacto.org/wp-content/uploads/BNFO_CostCalculator_BD_v1.0_160127.xlsx';
    $headers='Bcc: other@example.com' . "\r\n";

    // Email Message
    $mailBody="Volunteering at $message1\n\n
        Outputs: \n\n

        Productivity Gain Needed Amongst staff to cover cost: $message3 \n
        Decrease in Staff Turnover Required to Offset Cost:$message \n
        Total Cost £$message2 \n

        Inputs: \n\n

        Your Company's UK Headcount: $valuea\n
        Average Salary at your Company: $value \n
        Your Company's UK Operating Profit: $valueb\n
        Brokerage Costs: $valuec\n
        Anticipated Uptake: $valued\n

        Download the model here: $themodel \n\n
        ";

    mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>", $headers);
}

1 个答案:

答案 0 :(得分:1)

如果查看文档(http://php.net/manual/de/function.mail.php),邮件会接受标题作为第4个参数。您的第4个参数是“From”-line。第五个参数传递给邮件二进制文件(sendmail或其他任何东西,通常你不需要乱用它)。

您需要将BCC行附加到FROM行(两者都是标题)。试试这个:

$headers  = "From: $sender <$senderEmail>\r\n"
$headers .= "Bcc: other@example.com\r\n";

// ...

mail($recipient, $subject, $mailBody, $headers);