Sending mass mail using phpmailer

I am new to Phpmailer and I use it to send mass emails to over a thousand people from a noreply account. The code works great when I send email to one or two people, but when I send it to everyone (including me), it goes to spam. Another problem is the details of the email, which shows the email IDs of all the people to whom it was sent, which I do not want to do. The code is as follows:

//date_default_timezone_set('America/Toronto'); require_once('../class.phpmailer.php'); //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded $mail = new PHPMailer(); $mail->IsSMTP(); // telling the class to use SMTP $mail->Host = "smtp1.site.com;smtp2.site.com"; $mail->SMTPAuth = true;// enable SMTP authentication $mail->SMTPKeepAlive = true;// SMTP connection will not close after each email sent $mail->Host = "mail.yourdomain.com"; // sets the SMTP server $mail->Port = 26; // set the SMTP port for the server $mail->Username = " yourname@yourdomain "; // SMTP account username $mail->Password = "yourpassword"; // SMTP account password $mail->SetFrom(' noreply@mydomain.com ', 'List manager'); $mail->AddReplyTo(' list@mydomain.com ', 'List manager'); $mail->Subject = 'Newsletter'; $ids = mysql_query($select, $connection) or die(mysql_error()); while ($row = mysql_fetch_row($ids)) { $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; $mail->MsgHTML($body); $mail->AddAddress($row[0]); $mail->Send();//Sends the email } 
+4
source share
3 answers

As JoLoCo points out, the AddAddress() method simply adds a new address to the existing recipient list. And since you do it like an add / send cycle, you send a bunch of duplicate copies to the first recipient, one less to the second, etc.

What you need:

 while($row = mysql_fetch_row(...)) { $mail->AddAddress($row[0]); $mail->send(); $mail->ClearAllRecipients(); // reset the `To:` list to empty } 

On the other hand, since this is spam on your mail server with a large number of separate emails, another option is to create one SINGLE and BCC message for all recipients.

 $mail->AddAddress(' you@example.com '); // send the mail to yourself while($row = mysql_fetch_row(...)) { $mail->AddBCC($row[0]); } $mail->send(); 

This option is most likely preferable. You only generate one email and allow the mail server to do the hard work of sending copies to each recipient.

+12
source

I think that you are adding a new address to an already sent email, so the first email will be sent to one person, the second email sent will go to the same person plus another, the third will go to these two plus one more, and so on.

Also, I don't think you need to install AltBody and MsgHTML every time.

First you must add all the addresses in the BCC field, and then send.

So try ...

 // rest of code first $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; $mail->MsgHTML($body); $mail->AddAddress(" you@example.com ") $ids = mysql_query($select, $connection) or die(mysql_error()); while ($row = mysql_fetch_row($ids)) { $mail->AddBCC($row[0]); } $mail->Send();//Sends the email 
+3
source

Use BCC (Blind Carbon Copy) to hide the recipient list. Associated with the problem of spam, it depends on the recipient of the email provider what is going to spam and what is not, and there are many factors.

+2
source

All Articles