I’m trying to include a list of recipients to the phpMailer script but with no success. It just prints out the list but doesn’t include it in the function.
The file has to be external because it is part of an automated script that runs for different scenarios for different recipients.
Any ideas?
recipients.php
$mail->AddAddress('blabla@xyc.com');
$mail->AddAddress('gaga@xyz.com');
phpMailer.php
$mail = new PHPMailer(true);
try {
include('recipients.php');
$mail->AddCC('zyx@cba.com');
$mail->SetFrom('xyz@abc.com');
$mail->Subject = 'Subject Line';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
$mail->MsgHTML($email_message);
$mail->IsHTML(true);
$mail->Send();
echo "Message Sent OK</p>\n";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
If you want to follow phpMailer’s defined interface, I would suggest Gautam3164’s method too.
As you can only add one email address per function call.
phpMailer is not built for mailing list purpose.
Otherwise, I would hack into AddAnAddress method of phpMailer perhaps add your own “mass address loading” method.
Or use other library for sending emails to multiple recipients.
Hope this helps