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 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化