How to send emails to 190 people in my SQL database using PHP mail()
Hello, I'm hoping someone can help me.
I have a MYSQL Database with 190 records (emails/names/etc). I want to send an email to everyone in that table with a personalized greeting (Dear ______,).
How do I loop through the records to pull out the names/emails?
Thank you for any help
Batch process 40-50 at a time, put the first as "to" and "bcc" the rest assuming no limitations from your host. Lower the number if excessive delays. This is best done via a scheduled cron job at a time when the server has the least amount of usage.
As to code to make it happen give the first part of what I said a try, post code here after a good attempt and we'll help you out if you need it. Hint, use the limit in your query and keep track of the offset if you're familiar with PHP/MySQL and how to send basic email.
We don't know your skill level as to PHP, MySQL or cron, let us know.
Last edited by SrWebDeveloper; 02-26-2010 at 02:01 PM.
Do a query as you normally would for email address and name, then do a loop on the query result set, prepending the name to the message string and using the email address in the chosen mail function. PHP's native mail() function is rather inefficient for mass mailings, so you might want to consider using the PEAR::Mail_Queue package -- especially if you think there may be a lot of growth to your mail list (or one of the several 3rd-party mass mailing scripts out there on the 'net).
think i got it working--question about what you said
Why do I need to do this in batches?
I don't want to do anything as BCC as each message will require a personal Dear XXXX.
Can I do batches of 50 at a time all using just the to: field?
For the custom greeting each would have to be sent separately to one address.
Ah, I missed the personalization part, my apologies. Yeah, you'll need to send one at a time, if the greeting is crucial to the mailing. Batches are used (when mass mailing the same subject/body to different recipients) to reduce overhead, as sending one email at a time is very resource intensive, i.e. memory, bandwidth, the MTA i.e. sendmail, mail queue, DNS hostname lookup, log updating and so on. There is typically a delay between batches so the server can recover those resources for the next batch. And if the server is used for other things, i.e. web or apps, scheduling the mail to be sent when things are slow is wise.
Originally Posted by realmuffin
Last edited by SrWebDeveloper; 02-26-2010 at 07:13 PM.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread