Hi guys,
Firstly, awesome forums. Going to be spending a lot of time here I think. Anyways, I'd like to get your input and suggestions on how to go about sending a newsletter to my database of users.
I have a community web site running phpBB 3, and members also have a second login for adding content to my site using a CMS that I built for the job.
I would like to send out a newsletter to all the email addresses in my phpBB users table, and also those in the other users table.
Up until now I have been using phplist. But it doesn't share the same database. Every time I want to send an email, I have to update the list of users in phplist by exporting all the email addresses from phpBB and inserting them into phplist. It's a pain.
I really want to do something more automated than this. Now I know how to create and send AN HTML email using PHP. No Sweat. I was going to try just running a do / while loop until it had run through all the users. But my friend told me that my php script would time out before it sent to everyone. He said that there was a more suitable method for sending emails in large batches like this.
So my question is.. How does one go about sending a newsletter to all users in a database without taxing the system or having your PHP script timeout?
Obviously I'd have to send in batches etc etc.. but thing that I'm unsure about is what do I use to send the emails if my script is just going to time out?
Any help is greatly appreciated.
Kind Regards
Scott
Send an HTML email to all users in database
Moderator: General Moderators
-
scottrichardson
- Forum Newbie
- Posts: 9
- Joined: Wed May 21, 2008 12:14 am
Re: Send an HTML email to all users in database
Use Swiftmailer and read this http://www.swiftmailer.org/wikidocs/v3/faq/hugebatches
-
scottrichardson
- Forum Newbie
- Posts: 9
- Joined: Wed May 21, 2008 12:14 am
Re: Send an HTML email to all users in database
Hey there,
Awesome stuff. Been checking this out.
OK, so, can you just confirm that I can do what I wanna do, using the following method:
(note the previous page would be a simple form with a text box for the HTML I want to send, and a text field for the subject line. At the top of the mail script page I would do a database query on my users table, and source all the email addresses, then run a loop to add all the recipients)
Will this work?
Also, do I need to "addSlashes" to the HTML body of the email that was previously pasted into the previous page's text box?
I know there are custom list iterators, but I don't get them.. hehe.. so hoping this method will do okay?
Scott
Awesome stuff. Been checking this out.
OK, so, can you just confirm that I can do what I wanna do, using the following method:
(note the previous page would be a simple form with a text box for the HTML I want to send, and a text field for the subject line. At the top of the mail script page I would do a database query on my users table, and source all the email addresses, then run a loop to add all the recipients)
Code: Select all
$weeklySubject = $_POST['subject'];
$weeklyNewsletter = $_POST['htmlbody'];
$swift =& new Swift(new Swift_Connection_SMTP("host.tld"));
$message =& new Swift_Message("$weeklySubject", "$weeklyNewsletter");
$recipients =& new Swift_RecipientList();
do {
$recipients->addTo("recipient1@address.tld", "Recipient 1");
} while ($row_users = mssql_fetch_assoc($users));
$batch =& new Swift_BatchMailer($swift);
$batch->setSleepTime(10); //Sleep for 10 seconds if an error occurs
$batch->send($message, $recipients, new Swift_Address("company@domain.tld", "Our Company"));
$batch->flushFailedRecipients();
Also, do I need to "addSlashes" to the HTML body of the email that was previously pasted into the previous page's text box?
I know there are custom list iterators, but I don't get them.. hehe.. so hoping this method will do okay?
Scott
-
scottrichardson
- Forum Newbie
- Posts: 9
- Joined: Wed May 21, 2008 12:14 am
Re: Send an HTML email to all users in database
any word on this?