PhpMailer for multiple email address

Hi, I’m new to phpmailer and I’m trying to send an email to a group of users. I’ve searched on Google and used also the phpmailer reference guide and this is what i’ve created so far. I’m using amazon ses smtp and i’ve configured all the parameters into a function called smtpmailer

// Imposto l'oggetto della email
			$oggetto_email = 'Kondo Manager: nuova comunicazione condominio';
			// Creo il link per il login
			$link_login = BASE_URL . '/index.php';
			// Ottengo il tema html per il layout della email
			$message = file_get_contents(BASE_URL .'/email-templates/client-new-group-post.html');
			// Passo la variabile link a %linkripristino% che poi inserisco nel tema 
	    	$message = str_replace('%linklogin%', $link_login, $message);
	    	$message = str_replace('%titolo%', $group_message_subject, $message);

	    	$user_emails = mysqli_prepare($conn, "SELECT user_email FROM user_group_join LEFT OUTER JOIN users ON user_group_join . user_join_id = users . user_id WHERE group_join_id = ?");
	    	mysqli_stmt_bind_param($user_emails, 'i', $group_id);
        	mysqli_stmt_bind_result($user_emails, $tot_user_emails);
        	$tot_users_emails = mysqli_stmt_num_rows($user_emails);
        	// Inserisco le emails dentro ad un array
        	$emails = array();

        	if($tot_users_emails > 0){


	        		$emails[] = $tot_user_emails;


	    	foreach ($emails as $email) { //This iterator syntax only works in PHP 5.4+
	    		// uso la funzione smtpmailer per inviare la mail passando i parametri richiesti
				$send_mail = smtpmailer($email, $oggetto_email, $message);
				// controllo la presenza di possibil errori nell'invio
						if($send_mail === 'fail') {

							echo "Ops, si è verificato un problema! Non è stato possibile inviare la mail di notifica al cliente, ti consigliamo di riprovare oppure di contattare l'amministratore di sistema";


It seems to work fine but i’ve only tested with a group of three emails, i’m wondering if this is the right approach and if it will be still fine with a big group of emails 50-100 for example. Many thanks for your help

On the face of it I can’t see anything obvious that would change if you send 50, 100 or more emails through that code, if it works for the small test number, unless the time in doing so caused the browser to time out while they are being processed.

The only suggestion I would make is with your error message - it doesn’t give you any clue as to which email failed to send, just tells you “email failed” (I presume that’s what it says) for each one. You could just set a Boolean flag to tell you that one or more failed, set a counter to say how many failed, or modify the error message to show something like the value of $email that failed.

Hi @droopsnoot thanks for your answer. I’ve tested on a group of 20 emails and noticed that the browser takes some time to process the request, even if there is no server timeout I was thinking of a better way to optimise customer experience. I’ve managed to put a loading gif so at least they are aware something is happening. I read that sending multiple email using addbcc would save some time is it correct? I also read something about putting emails in a queue and then send them but I’m not sure how to do it

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.