Forum Moderators: coopster

Message Too Old, No Replies

Automated email script

         

neophyte

5:01 am on Apr 28, 2005 (gmt 0)

10+ Year Member



In a few days I need to start coding a little function that will take email addresses from a mysql table - tack

on a generic subject line and some boilerplate message text - and then automatically email this message to all

addresses found in the DB table.

To me, this sounds conceptually simple enough (as a Neophyte):

a. drop a generic subject line into a variable named $subject;
b. drop the boilerplate text into a variable named $message;

c. create a loop for the number of rows in the table;
d. feed the email address found in each row into an $email variable;
e. send the email using mail($email, $subject, $message, "From: example@example.com");
f. loop repeats

This seems like it would work, but at the same time, it seems too simple.

Am I missing something that I need to consider for something like this?

Neophyte

RonPK

8:09 am on Apr 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It should work.
If you're sending out large numbers of identical mails, it may be a good idea to group the addresses by domain. That should make life easier for the mail program (less DNS lookups).

So if you're sending mail to
jack@example.com , sue@example.com and bill@example.net,
put jack and sue in the same To: field. Or in the Bcc: field, if you want to hide their addresses.

The downside of this method is that some spam filters may block the mail.

ncreegan

10:24 am on Apr 28, 2005 (gmt 0)

10+ Year Member



mail() can be pretty slow, and detrimental to resources when being looped. I'd avoid putting more than a couple addresses in the to: line, it seems to upset people and filters.

I just have to ask what is the point of sending out a bunch of generic e-mails? If you're trying to market to these people, be sure of what you are getting into, there's no quicker way to piss off your users, your host, isp, etc than to mass mail...

neophyte

10:44 am on Apr 28, 2005 (gmt 0)

10+ Year Member



Thanks RonPK for your suggestion.

necreegan:

This particular client is a new author. He's allowing people to download the first chapter of his book. Before downloading, they are required to complete a short form with their name, email address, city and country. There is also a check box which says "Notify me when the book is available". If they click the box, their information goes into the DB. If they don't, it doesn't.

When the book is released, the author wishes to notify all those - who wanted to be notified - of the book being available.

That's the reason and purpose of this. It is my understanding that if someone requests further information then it is not considered spam.

To your point, I will only be sending one email to one person at a time so I don't think the server overhead will be too severe. If you think I am wrong about that, please reply. This is the first time I have done anything like this.

Thanks for your input.

ncreegan

11:58 am on Apr 28, 2005 (gmt 0)

10+ Year Member



the problem with the conventional mail() function is that it connects to socket, sends mail, connects to socket, sends mail, etc. It's better form, when mailing to more than a few recipients, to connect to a socket, mail all, and disconnect. You can search for socket mailing on google. Of course if you only have a few hundred recipients, you can just send the mail in batches and not have to worry about resources or (more) complex code.

As for mailing permissions, it's amazing how fast people forget that they signed up for something. Be sure to record the IP address and date signed up in addition to the info you're collecting, it can save you headaches later down the road. Using a double opt in method can also help you keep complaints away.

neophyte

3:18 pm on Apr 28, 2005 (gmt 0)

10+ Year Member



> It's better form, when mailing to more than a few recipients, to connect to a socket, mail all, and disconnect. You can search for socket mailing on google.

Thanks for this tip. Don't know anything about it but I'm game to learn. I'll do a search for this socket mailing thing as suggested. Thanks!

jatar_k

4:10 pm on Apr 28, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



sent out 20k a couple of weeks ago, we sent it out piece by piece using a cron, 100 at a time over a couple of days.

things to watch

1. make sure you propely construct your mail headers

2. run your email message through a server with spam filters (we use spam assassin) and take a look at what x-spam-status it gives you, it will also give you the flags that it tripped and you can remove the offending words/formatting.

3. you will get reported, as ncreegan mentioned, people forget they signed up and will report you, cover yourself for that

4. don't send out massive amounts of email at once, your isp will either burn them so they cease to exist or they will shut down your account, fun stuff. Remember also that the mail function likes to be a hog and your host may get very upset if you are sending 5k email for an hour and taking up a chunk of shared resources.

5. your email will not get through to everyone, even with all precautions and testing it will still get junked

6. test it with multiple free email accounts and various clients and their spam filtering, this will maximize the number of people it gets through to

7. if you use a cron, make sure it notifies you when it is done, that you have some way of keeping track who got what when and that it takes into account when there are no emails left so it doesnt throw errors. Mine sent me text messages when it was done. Also do your calculations so that if you have to login and stop the script it isn't at 4am.

that's all I can think of before coffee ;)

neophyte

11:33 pm on Apr 28, 2005 (gmt 0)

10+ Year Member



Thanks jatar_k.

This is starting to get complicated for my simple mind.

What is a "cron?"

jatar_k

11:43 pm on Apr 28, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



a method of scheduling a scripts execution

[google.com...]

I think windows calls it 'scheduled tasks' or something