i am allowing user to enter multiple emails by comma separated . and i am taking those emails and sending them email all. want to send emails to Bcc.
i want to send them email separately , but here is the screenshot
my PHP code is :
$Email = new PHPMailer;
$Email->IsSMTP();
$Email->Host = "mail.cliqueipet.com.br";
$Email->SMTPAuth = false;
$Email->IsHTML(true);
$Email->Username = "xxxx";
$Email->Password = "xxxx";
$Email->SMTPSecure = "tls";
//$Email->SMTPDebug = 2;
$Email->From = "convites@xxx.com.br";
$Email->CharSet = "UTF-8";
$Email->FromName = $Nome . " - Festa na Vila das Pitangas";
//here is i am adding address
for($i=0; $i<count($email); $i++):
$Email->AddAddress($email[$i]);
endfor;
$Email->Port = 587;
$Email->Subject = " Convite para festa de $Nome na Vila das Pitangas. ";
$toEmails = array('xyz@gmail.com','abc@gmail.com');
for($i=0; $i<count($toEmails); $i++):
$Email = new PHPMailer;
$Email->IsSMTP();
$Email->Host = "mail.cliqueipet.com.br";
$Email->SMTPAuth = false;
$Email->IsHTML(true);
$Email->Username = "xxxx";
$Email->Password = "xxxx";
$Email->SMTPSecure = "tls";
//$Email->SMTPDebug = 2;
$Email->From = "convites@xxx.com.br";
$Email->CharSet = "UTF-8";
$Email->FromName = $Nome . " - Festa na Vila das Pitangas";
$mail->addAddress($toEmails[$i]);
$mail->Subject = 'Convite para festa de $Nome na Vila das Pitangas.';
$mail->Body = '<your mail body here>';
if(!$mail->send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
endfor; //this should end when ur first email sent
This should work will send 1 mail at a time in the loop.
You have to use the addBCC
function
Lets say that emails are saved as a string separated with ; from each other (you need to iterate through them and add each email to BCC with the addBCC
function)
$bcc_emails_str = "info@live.com;other@hotmail.com";
$bcc_emails_array = explode(";", $bcc_emails_str);
foreach($bcc_emails_array as $email)
{
if (filter_var($email, FILTER_VALIDATE_EMAIL))
{
$mail->addBCC($email);
}
}
For further information read the PHPMailer documentation