Azima:
I'm using phpMailer to send Emails. Email recipients are passed as an array, and are added by looping through this array. Example:
public static function mailTo($recipients)
{
$f3 = \Base::instance();
$user = AclHelper::getCurrentUser();
$template= new \Template;
$mailBody= $template->render('leave/emailTemp.html');
// When true, PHPMailer returns exceptions
$mail = new PHPMailer(true);
try {
$mail->isSMTP(); // Set mailer to use SMTP
$mail->isHTML(true);
$mail->addAddress($user['email']);
$mail->addAddress("[email protected]");
$mail->addAddress("[email protected]");
foreach($recipients as $recipient){
$mail->addAddress($recipient);
}
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->Username = "[email protected]";
$mail->Password = "abcd";
$mail->setFrom($user['email']);
$userFullName = trim(ucfirst($user['firstname'])) . " " . trim(ucfirst($user['lastname']));
$mail->FromName = $userFullName;
$mail->Body = $f3->get('message');
$mail->Body .="
". $mailBody;
$mail->Subject = 'Updates on leave date applied';
$mailStatus = (boolean)$mail->send();
if ($mailStatus === true) {
return $mail;
}
} catch (phpmailerException $e) {
$response = array(
'status'=>'error',
'message'=>'Got some error while sending emails',
'exceptions'=>$e->getMessage()
);
return $response;
} catch (Exception $e) {
$response = array(
'status'=>'error',
'message'=>'Got some error while sending emails',
'exceptions'=>$e->getMessage()
);
return $response;
}
}
Emails are being sent to and received by recipients whose addresses are set statically. eg.
$mail->addAddress("[email protected]");
$mail->addAddress("[email protected]");
The problem is that there might exist some "invalid" emails among these recipients. For eg. "[email protected]"
.
It seems that whenever phpMailer encounters these type of addresses, it doesn't send emails to any other "valid" addresses as well.
How can I make PhpMailer work such that "valid" emails receive emails like in Gmail.
Any help is very much appreciated. Thanks.
Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE