问题
Im having a big problem here! I need to send a newsletter to all my subscribers (around 1200) The thing is that it only sends the newsletter to 150-180 of them. I have a script implemented in php that uses the PhpMailer() class to send the newsletter to all the subscribers.
I purchased a plan in MailJet that allows me to send 30 thousand emails per month, so Im using their SMTP host to send the newsletter.
Here is my script:
$mail = new PHPMailer();
$body = $message;
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "in.mailjet.com";
$mail->Port = 80;
$mail->Username = "username";
$mail->Password = "password";
// thing regarding the body, subject, etc of the email //
$to_list = explode(',',$to);
$between_delay = 75; //max limit of mails send at a slot
$send_count = 1;
$send_delay = 1; //Delays the program execution for the given number of seconds.
ignore_user_abort(true); // Ignore user aborts and allow the script to run forever
set_time_limit(300); //to prevent the script from dying
foreach($to_list as $row){
if ( ($send_count % $between_delay) == 0 ){
sleep( $send_delay ); //Delays the program execution for the given number of seconds.
}
$address = $row;
if(!empty($address)) {
$mail->AddAddress($address, "User");
$mail->Send();
$mail->ClearAddresses(); //clear address
}
$send_count++;
}
if(!empty($mail->ErrorInfo)) {
// display an error
}
I really dont know what may be the problem but for some reason it stops sending emails after the number 180 approximately. Could it be something regarding the set_time_limit(300); ??
回答1:
I don't recommend sending a copy of the newsletter to each individual email address; it wastes bandwidth and forces your script to send multiple copies of the message.
Instead, consider using the blind-carbon-copy (BCc) feature of your SMTP server to send the mass email. This will allow your SMTP server to optimize the delivery of the newsletter, and it will save you bandwidth as well.
A quick lookup of the PHPMailer API says you can add BCc'd addresses using the $mailer->AddBCC()
function. For example, $php_mailer->AddBCC('somebody@example.com', 'Joe Somebody');
should work.
回答2:
Just to update this post, Mailjet now has an easy to use PHP wrapper to send your emails and perform any requests on our new REST API.
You can find it on Github here and the complete documentation here.
来源:https://stackoverflow.com/questions/14086667/phpmailer-cannot-send-newsletter-to-large-amount-of-subscribers