6

I have been testing the following code for hours. The email will send to the addresses added through $mail->AddAddress() and in the received email it states the cc but the person cced does not receive the email. I have looked everywhere and can not find a solution to why this is happening. I have run tests and all variables are being submitted to this code properly.

My server is running Linux Red Hat

My Code:

require_once('../smtp/class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try {
  $mail->SMTPDebug  = 0;                     // enables SMTP debug information (for testing)
  $mail->SMTPAuth   = true;                  // enable SMTP authentication
  $mail->SMTPSecure = "tls";                 // sets the prefix to the server
  $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
  $mail->Port       = $port;                 // set the SMTP port for the GMAIL server  465 or 587
  $mail->Username   = $username;             // GMAIL username
  $mail->Password   = $password;             // GMAIL password

  // Add each email address
  foreach($emailTo as $email){ $mail->AddAddress(trim($email)); }
  if($cc!=''){ foreach($cc as $email){ $mail->AddCC(trim($email)); } }
  if($bcc!=''){ foreach($bcc as $email){ $mail->AddBCC(trim($email)); } }

  $mail->SetFrom($emailFrom, $emailName);
  $mail->AddReplyTo($emailFrom, $emailName);
  $mail->Subject = $subject;
  $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
  $mail->MsgHTML($content);
 // $mail->AddAttachment('images/phpmailer.gif');      // attachment
 // $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment

  $mail->Send();
  echo'1';exit();
} catch (phpmailerException $e) {
  echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
  echo $e->getMessage(); //Boring error messages from anything else!
}
Douglas Cottrell
  • 271
  • 2
  • 5
  • 13
  • What do your mail logs say? – Crontab Feb 04 '13 at 16:50
  • 1
    This line: `if($cc!=''){ foreach($cc as $email){ $mail->AddCC(trim($email)); } }` Shows a string comparison, and then an array operation. Which format is your data? – Sammitch Feb 04 '13 at 17:18
  • I found the issue. For some reason It was not sending the cc because I had the to email address in the cc list. For some reason that was kicking it. As soon as i removed that one from the cc list is sent perfectly. – Douglas Cottrell Feb 05 '13 at 22:21
  • possible duplicate of [Phpmailer AddBcc not working](http://stackoverflow.com/questions/12777862/phpmailer-addbcc-not-working) – John Magnolia Dec 30 '14 at 20:28

2 Answers2

10

Old question, but I ended up here looking for an answer. Just learned elsewhere that those functions AddCC and AddBCC only work with win32 SMTP

Try using:

$mail->addCustomHeader("BCC: mybccaddress@mydomain.com"); 

See http://phpmailer.worxware.com/?pg=methods

Hope this helps someone, cheers!

i_a
  • 2,660
  • 1
  • 18
  • 20
-1
$address = "xxxxx@gmail.com";
$mail->AddAddress($address, "technical support");


$address = "yyyyyy@gmail.com";
$mail->AddAddress($address, "other");


$addressCC = "zzzzzz@gmail.com";
$mail->AddCC($addressCC, 'cc account');


$addressCC = "bcc@gmail.com";
$mail->AddBCC($addressCC, 'bcc account');
Rugmangathan
  • 2,958
  • 6
  • 31
  • 42
user2823361
  • 101
  • 5