Using multiple email address for posting mails from PHPMailer class

PHPMailer We may have a list of email address to which the common message should go. For this we will store all email address in an array and then we will loop through the array to add all emails to our outgoing address.

Let us say we have 5 address in an array
$address = array('','',
We will follow the instruction given on how to display elements of an array to display all the address.

Above code is a sample to display all email address but our requirement is to add them to our mail outgoing list. You can see our mail posting script using PHPMailer class here. To this script we will add the array looping like this.

$bodytext=' This is the body of the test mail ';
$subject= 'plus2 Message Subject'.date(" H:i:s", time());
$address = array('','',

$email = new PHPMailer();
$email->From = '';
$email->FromName = 'Your Name';
$email->Subject   = $subject;
$email->Body      = $bodytext;

while (list ($key, $val) = each ($address)) {

 echo "Mailer Error: " . $email->ErrorInfo;
 echo "Message has been sent successfully";

Collecting email address from a table

Like above code we can collect all email address from a table and use them to send emails to all. You can read how to display data from table here. Same code we will use to add address to our phpmailer class.
$sql="select email from table_name ";
foreach ($dbo->query($sql) as $row) {

Using BCC

You may not be interested to show all address to each member of your list, in such a case you can add BCC to each address. You can only change above line in respective AddAddress line.
$email->AddBCC($row[email]);//data taken from table
$email->AddBCC($val);//data taken from array
PHP Mail PHPMailer class PHPMailer class using SMTP Feedback form to post visitor details to site admin by email PHP Ajax feedback form
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer