mass mailing with php

111 Views Asked by At

I have a database containing more than 2000 contacts, I want to use the mass mailing, but I do not know how to do it, I used this code but I think it is not useful because the number of mails is important and mail() can't work for mass mailing.

<?php

require ("bdd.php");

$sql = "SELECT adresse FROM newsletter WHERE envoie='1';";
$result = mysql_query($sql);

while($row = mysql_fetch_array($result))
{
     $en_tete ='From: '. $row['adresse'] .''."\n";
     $en_tete .='Reply-To: [email protected]'."\n";
     $en_tete .='Content-Type: text/html; charset="iso-8859-1"'."\n";
     $en_tete .='Content-Transfer-Encoding: 8bit';
     $contenu ='<html><head><title>Envoie html</title></head><body><p>TEST !</p></body></html>';

     mail($row['adresse'], 'Envoie mail', $contenu,  $en_tete)
}

mysql_close();

?>
1

There are 1 best solutions below

0
Dr Manish Lataa-Manohar Joshi On

You can use PHPMAILER

I don't know whether below solution is useful for you or not.. But I am just suggesting alternative thinking to send mass emails without any issue like spamming or hosting provider's limit of email per hour etc.....

========

Additionally you can use your query with limit and update database column when email sent...

e.g.

Add additional column 'email_sent' in your database table...

and change query to

$sql = "SELECT adresse FROM newsletter WHERE envoie='1' and email_sent='0' order by id desc limit 25"; 
 // Limit can be any...10 or 25 or 50 etc... this will limit total emails at a time...


//in while clause, add query to Update database >> `email_sent`=>1...

With cronjob you can reset email_sent to 0 again....or with simple link to script which contains query to reset / update email_sent to 0 for all 2000+ rows can be used...

Please avoid mysql...... Try Mysqli or PDO rather..