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