I need help with PHP code that sends automated email receipts to customers. The problem is the customer can see the bcc email address. Can you help me with what code is needed to make the bcc field blind to customers?
<?php
//change the email parameters as required.
//$ccEmail="
[email protected]";
$formName="xxxx"; //set the form name as required.
$fromEmail="
[email protected]"; //set the form email as required.
$subject="Your Order Receipt"; //set the subject of the email.
$bccEmail="
[email protected],
[email protected]";
define("ROOT_PATH","/path/xxxx.com/web/content/");
$fields_string = "";
foreach($_POST as $key=>$value) {
if($fields_string != "") {
$fields_string .= "&";
}
$fields_string .= $key."=".urlencode($value);
}
$stringval=rtrim($fields_string);
include_once("email_format.php");
//uncomment one of the two lines below to toggle test and live mode.
$toEmail=$payer_email; //live mode - uncomment to send to buyers email
//$toEmail="
[email protected]"; // test mode - uncomment to send to
[email protected] for testing
if($strTemplate!=""){
WriteLogFile($stringval);
SendEmail();
//echo $strTemplate;
}
function WriteLogFile($stringname){
$today = date("F j, Y, g:i a");
$myFile = ROOT_PATH . "website/xxxx/log/log.txt";
if(file_exists($myFile)){
$fp = fopen($myFile, 'a') or die("can't open file");
fwrite($fp,$stringname . "\n" . $today . "\n");
fclose($fp);
}
return true;
}
function SendEmail(){
global $formName,$toEmail,$ccEmail,$bccEmail,$strTemplate,$subject,$fromEmail;
require_once "Mail.php";
//$from = "
[email protected]";
$from = $fromEmail;
$to = $toEmail;
$body = $strTemplate;
$cc=$ccEmail;
$bcc=$bccEmail;
/*$host = "smtp.emailsrvr.com";
$username = "XXXXX";
$password = "XXXXX";
$host = "smtp.emailsrvr.com";
$username = "
[email protected]";
$password = "xxxxxx";
*/
$host = "smtp.mailgun.org";
$username = "
[email protected]";
$password = "xxxxxxxxxx";
if(!empty($cc) && !empty($bcc)){
$headers = array ('From' => $formName . '<' . $from . '>',
'To' => $to,
'Cc' => $cc,
'Bcc' => $bcc,
'Subject' => $subject,
'Content-type'=> 'text/html',
'charset'=> 'iso-8859-1');
}
if(empty($cc) && !empty($bcc)){
$headers = array ('From' => $formName . '<' . $from . '>',
'To' => $to,
'Bcc' => $bcc,
'Subject' => $subject,
'Content-type'=> 'text/html',
'charset'=> 'iso-8859-1');
}
if(empty($bcc) && !empty($cc)){
$headers = array ('From' => $formName . '<' . $from . '>',
'To' => $to,
'Cc' => $cc,
'Subject' => $subject,
'Content-type'=> 'text/html',
'charset'=> 'iso-8859-1');
}
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => 587,
'auth' => true,
'username' => $username,
'password' => $password));
if(empty($recipients)){
$recipients = $to;
if(!empty($cc)){
$recipients.= "," .$cc;
}
if(!empty($bcc)){
$recipients.= "," .$bcc;
}
}
echo $recipients;
//die($recipients);
$mail = $smtp->send($recipients, $headers, $body);
if (PEAR::isError($mail)) {
//echo("<p>" . $mail->getMessage() . "</p>");
WriteLogFile($mail->getMessage());
die($mail->getMessage());
} else {
//echo "Email sent through Server SMTP to " . $recipients;
WriteLogFile("Email sent through Server SMTP to " . $recipients);
return true;
}
}
?>