Page 1 of 5
how to send 2300 emails without errors?
Posted: Wed Aug 02, 2006 3:58 pm
by alexus
Hi,,
I need advice..
I have 2300 emails in DB and I want to create Newsletter generator.... so the qiestion is this :
1. wil mail() function will be able to hanmdle this many emails in CC field or should I do LIMIT 0, 100 etc
2. Should I send the emails row by row? how can I work around with max exec time then?
Any advice? Thnx
And yea, I cant really play around because ppl might get angry of getting test emails he he
Posted: Wed Aug 02, 2006 4:01 pm
by RobertGonzalez
1) Read my sig.
2) Download SwiftMailer.
3) Install it.
4) Use it.
5) Celebrate over beers with d11wtq.
Posted: Wed Aug 02, 2006 6:14 pm
by Chris Corbyn
... and here's a tip for once you've learned the basics:
http://www.swiftmailer.org/documentation/66#view
Posted: Mon Aug 07, 2006 4:03 pm
by alexus
Ok i just tried to use SWIFT for batch mailing with AntiFlood but its aint working

(Works without antiflood though)
Can some one help me on tweaking the antiflood?
Here is what i did:
Code: Select all
<?php
require('../../Swift.php');
require('../../Swift/Connection/SMTP.php');
require('../../Swift/Plugin/AntiFlood.php');
$recipients = array(
'myemail@example.com',
'myemail@example.com'
);
$mailer = new Swift(new Swift_Connection_SMTP('mail.example.com'));
//If anything goes wrong you can see what happened in the logs
$swift = new Swift($connectionObject);
//100 mails per batch with a 30 second pause between batches
$swift->loadPlugin(new Swift_Plugin__AntiFlood(100, 30));
if ($mailer->isConnected())
{
//Add as many parts as you need here
$mailer->addPart('Some plain text part');
$mailer->addPart('Some HTML <strong>part with bold</strong> text', 'text/html');
$mailer->AddBcc($recipients);
//Make the script run until it's finished in the background
set_time_limit(0); ignore_user_abort();
echo "Close the browser window now...";
flush(); ob_flush();
//You can call authenticate() anywhere before calling send()
if ($mailer->authenticate('username', 'password')) {
//Leaving the body out of send() makes the mailer send a multipart message
$mailer->send(
'"Ultra Newsletter" <newsletter@example.com>',
'"Ultra Newsletter" <newsletter@example.com>',
'Some Subject'
);
}else echo "Didn't authenticate to server";
$mailer->close();
}
else echo "The mailer failed to connect. Errors: <pre>".print_r($mailer->errors, 1)."</pre><br />
Log: <pre>".print_r($mailer->transactions, 1)."</pre>";
?>
Im getting this error:
Fatal error: Call to a member function on a non-object in /home/elite/public_html/ultra/inc/Swift/Swift.php on line 297
Posted: Mon Aug 07, 2006 4:15 pm
by RobertGonzalez
Are you using the right version of Swift for your PHP version?
Posted: Mon Aug 07, 2006 4:18 pm
by alexus
yap, i downloaded the PHP5 version first but then is didnt work even with basic mailing so I figured that "interface" class is not supportrd in v4 so now im using riht one... all works with authentication and batch mailing, but now I want to add anti-flood in the script and it throws me all kinds of errroes
Posted: Mon Aug 07, 2006 4:20 pm
by Chris Corbyn
You've instantiated swift twice and are using variables from pseudo code that don't even exist. You also have an extra underscore on the plugin name.
I don't know why you're sending to the all as Bcc recipients.... they just go in the "To:" list. Sending as Bcc with no To: address will likely be blocked as spam.
Remember to change the username and password and to also change the smtp server.
Code: Select all
<?php
require('../../Swift.php');
require('../../Swift/Connection/SMTP.php');
require('../../Swift/Plugin/AntiFlood.php');
$recipients = array(
'myemail@example.com',
'myemail@example.com'
);
$swift = new Swift(new Swift_Connection_SMTP('mail.example.com'));
//If anything goes wrong you can see what happened in the logs
//100 mails per batch with a 30 second pause between batches
$swift->loadPlugin(new Swift_Plugin_AntiFlood(100, 30));
if ($swift->isConnected())
{
//Add as many parts as you need here
$swift->addPart('Some plain text part');
$swift->addPart('Some HTML <strong>part with bold</strong> text', 'text/html');
//Make the script run until it's finished in the background
set_time_limit(0); ignore_user_abort();
echo "Close the browser window now...";
flush(); ob_flush();
//You can call authenticate() anywhere before calling send()
if ($swift->authenticate('username', 'password')) {
//Leaving the body out of send() makes the mailer send a multipart message
$swift->send(
$recipients,
'"Ultra Newsletter" <newsletter@example.com>',
'Some Subject'
);
}else echo "Didn't authenticate to server";
$swift->close();
}
else echo "The mailer failed to connect. Errors: <pre>".print_r($swift->errors, 1)."</pre><br />
Log: <pre>".print_r($swift->transactions, 1)."</pre>";
?>
Posted: Mon Aug 07, 2006 4:30 pm
by alexus
Ok that works! thanks!
Also in documentation it says that it will run as the background proces? does it mean that if youser opens new php page in same window the process wouldnt be interapted?
Can I output some debug info?
like say: Sending mail now... olease wait... mail sent to 1100 users ... 3 adresses do not exist?
Posted: Mon Aug 07, 2006 4:39 pm
by Christopher
What was that green reptilian flash! I think it was Swift Mailer Man!

Posted: Mon Aug 07, 2006 4:46 pm
by Chris Corbyn
alexus wrote:Ok that works! thanks!
Also in documentation it says that it will run as the background proces? does it mean that if youser opens new php page in same window the process wouldnt be interapted?
Can I output some debug info?
like say: Sending mail now... olease wait... mail sent to 1100 users ... 3 adresses do not exist?
RE backgrounding....
Yes the user can stop the page loading and navigate away without breaking the script. I wouldn't have a user executing a send to 2300 addresses though
I've not tested it but apprently this works if you don't want the user to have to kill the page loading:
Code: Select all
<?php
require('../../Swift.php');
require('../../Swift/Connection/SMTP.php');
require('../../Swift/Plugin/AntiFlood.php');
$recipients = array(
'myemail@example.com',
'myemail@example.com'
);
$swift = new Swift(new Swift_Connection_SMTP('mail.example.com'));
//If anything goes wrong you can see what happened in the logs
//100 mails per batch with a 30 second pause between batches
$swift->loadPlugin(new Swift_Plugin_AntiFlood(100, 30));
if ($swift->isConnected())
{
//Add as many parts as you need here
$swift->addPart('Some plain text part');
$swift->addPart('Some HTML <strong>part with bold</strong> text', 'text/html');
//Make the script run until it's finished in the background
set_time_limit(0); ignore_user_abort();
header('Location: somewhere_else.php'); //Redirect from page
//You can call authenticate() anywhere before calling send()
if ($swift->authenticate('username', 'password')) {
//Leaving the body out of send() makes the mailer send a multipart message
$swift->send(
$recipients,
'"Ultra Newsletter" <newsletter@example.com>',
'Some Subject'
);
}else echo "Didn't authenticate to server";
$swift->close();
}
else echo "The mailer failed to connect. Errors: <pre>".print_r($swift->errors, 1)."</pre><br />
Log: <pre>".print_r($swift->transactions, 1)."</pre>";
?>
RE: Debugging
If you have swift mailer 2 then there's a method called getFailedRecipients() which you can run at the end of sending. This will provide you with an array of addresses which was rejected by the SMTP server for whatever reason (badly formatted, non-existent domain, no MX record etc etc...).
Posted: Mon Aug 07, 2006 6:09 pm
by alexus
if im not mistakken what you changed in the script is:
" header('Location: somewhere_else.php'); //Redirect from page "
which will just do the same as if the user just leave the page,,, but that would prevent them to cancel the page execution
Ok I will play around and probably will get back in here!
Thanks for help!
PS: email will be send to 2300 users by admin he he... thats mass mailing to all our site members, hope we not going to spam list
Posted: Mon Aug 07, 2006 7:51 pm
by alexus
getting back about
getFailedRecipients ( )
how do I use that function? I tried just to do the output but got
Code: Select all
Fatal error: Call to undefined function: getfailedrecipients()
Please help!
Posted: Tue Aug 08, 2006 6:40 am
by Chris Corbyn
alexus wrote:getting back about
getFailedRecipients ( )
how do I use that function? I tried just to do the output but got
Code: Select all
Fatal error: Call to undefined function: getfailedrecipients()
Please help!
Code: Select all
print_r($swift->getFailedRecipients());
Posted: Tue Aug 08, 2006 6:59 am
by s.dot
/me would like to note he's used swift sending to 7000 emails =]
Posted: Tue Aug 08, 2006 11:25 am
by alexus
ok, when I outputed the failed addreeses it jyst gave me number "1" which is I assume 1 bad address or error, and it is probably my hotmail account that for soeme rasont doesnt get the maill I send from SWIFT, but works just fine with the same SMPT account. a)Why that happence and gow can I debug? I dont want to loose all hotmail accounts thats about 500 ppl in my database
Thanks!