dsdtumf776629385 2016-02-18 15:58
浏览 42
已采纳

Mail()BCC - 无法让它工作

I'm having a bit of trouble creating a mail function that sends form result - some calculations - to the user. It was working fine until I added a bcc header and now no email gets sent.

The pertinent code is below and the page can be seen here: http://benefacto.org/calculator/

This is my first major php project!

Here is my mail function:

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' . "
";

    // Email Message
    $mailBody="Volunteering at $message1


        Outputs: 



        Productivity Gain Needed Amongst staff to cover cost: $message3 

        Decrease in Staff Turnover Required to Offset Cost:$message 

        Total Cost £$message2 


        Inputs: 



        Your Company's UK Headcount: $valuea

        Average Salary at your Company: $value 

        Your Company's UK Operating Profit: $valueb

        Brokerage Costs: $valuec

        Anticipated Uptake: $valued


        Download the model here: $themodel 


        ";

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

1条回答 默认 最新

  • dousao6313 2016-02-18 16:11
    关注

    If you look at the docs (http://php.net/manual/de/function.mail.php), mail accepts headers as the 4th parameter. Your 4th parameter is the "From"-line. The fifth parameter is passed to the mail binary (sendmail or whatever, generally you don't need to mess with it).

    You need to append the BCC line to the FROM line (both are headers). Try this:

    $headers  = "From: $sender <$senderEmail>
    "
    $headers .= "Bcc: other@example.com
    ";
    
    // ...
    
    mail($recipient, $subject, $mailBody, $headers);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测