I've got a PHPMailer setup which works fine, but when I added BCC it begins to report error. I can't see what exactly causing this issue.
I've got this error report: You must provide at least one recipient email address.
The strange thing is, that it's sending the emails correctly to both recipients but never changes to my 'succes.php'-page. It just simply showing the error reporting.
I have tried almost any combination of ADD and Clear, but keep getting somekind of issue. What I'm facing now, does sends the emails, but still reporting error.
My setup is like this:
try {
// Ens for all
$mail->Host = 'localhost'; // SMTP server
$mail->AddReplyTo('no-reply@XXX.dk', 'XXX Mailer');
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
$mail->AddAddress("$email");
$mail->AddBCC("$bcc");
$mail->Subject = "$subject";
$mail->MsgHTML($message);
$mail->Send();
$mail->ClearBCCs();
$mail->ClearAddresses();
if(!$mail->Send()) {
header('Location: fejl.php');
} else {
header('Location: succes.php');
}
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
} // end of if !mail
else { //report the errors
echo 'TEST ERRORS';
foreach ($errors as $msg) { //prints each error
echo " - $msg<br />
";;
} // end of foreach
echo 'End';
} //end of if(empty($errors))