Send multiple emails at once using PHPMailer

In this tutorial I will show you how to send multiple emails at once using PHPMailer.

Example Code:

In following example we have an array of email and content to be sent. So we have created an object on PHPMailer and sending email in for loop.


$emailArray = array("","","");
$bodyArray = array("mail content for","mail content for", "mail content for");

$mail = new PHPMailer();
$mail->Timeout  = 360;

$totalEmails = count($emailArray);
for($i=0; $i<$totalEmails; $i++) {

	$mail->From = "";
	$from = "User Name";
	$mail->FromName = $from;	  
	$Email = $emailArray[$i];		
	$mail->AddReplyTo($Email, $from);		
	$to = $Email;
	$mail->AddAddress($to, "");		
	$mail->Subject =  'multiple email'; 		
	$mail->Body  = $bodyArray[$i];

Now most important part of this example is at the end. If you not mention “$mail->ClearAddresses();” , Then all email id except the last email will get multiple emails instead of 1 email.

$mail->ClearAddresses() is used to Clear all To recipients. If $mail->ClearAddresses() is not working, you can use $mail->ClearAllRecipients(); to Clear all recipient types.

Hope this tutorial will help you to send multiple email at once using PHPMailer.