Forum Moderators: coopster

Message Too Old, No Replies

Your Opinion PHP for mailing newsletter

Whether or not PEAR should be used to send out a newsletter

         

pniac

12:20 pm on Oct 4, 2005 (gmt 0)



I send about once a month a newsletter, to currently 250 people. This number is expected to grow. I have used mail() before, but now that there are 250 people this is not the preferred option. I've been reading that the PEAR:mail class would be a good option.

Do you agree? I do not need any advanced options. The only requirement is that I can send out HTML e-mails to many people, with a customized message for everybody (because everybody has a different UNSUBSCRIBE link), using PHP.

Thanks,

Paul

pniac

2:32 pm on Oct 5, 2005 (gmt 0)



Any idea... anybody?

r3nz0

3:10 pm on Oct 5, 2005 (gmt 0)

10+ Year Member



High,

You have to know that PHP has something with Timeout.. so alot of email's could be a problem if you dont make a frame with refresh or something...

chrisjoha

3:17 pm on Oct 5, 2005 (gmt 0)

10+ Year Member



No, you could just keep setting set_time_limit(30); until you're done. OR, run the program in the console where timeouts don't affect it. I think mailing out newsletters with Pear is a good idea!

pniac

3:28 pm on Oct 5, 2005 (gmt 0)



Thanks for your replies.

For what I understand, I will have problems with the script run time if I use regular mail(). But do I have the same problem with PEAR? Because I thought that would be the kind of problem that would be solved when using PEAR.

coopster

3:29 pm on Oct 5, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Hi pniac and welcome to WebmasterWorld.

Are you having issues right now sending out email? The PEAR class you refer to basically has 3 options if I remember correctly -- the PHP mail() function, a "sendmail" option and an "SMTP" option.

If you were to invoke the PEAR class and just use the "mail" factory, you haven't really done anything different. I believe the same would hold true if you invoked the "sendmail" factory because that is simply passing the parameters to the sendmail utility via command line. The "SMTP" option would be a bit different though in that you are opening a socket directly to the SMTP server rather than *relay* via any sendmail utility.

pniac

4:11 pm on Oct 5, 2005 (gmt 0)



Thanks coopster.

The problem right now is that the mail() function starts to get slow, and given the expectation that more e-mail need to be send out in the future, I expect this problem only to worsen.

I have also read about those three options of PEAR. The SMTP option would be the one I need then, right? Do you have any experience with this? Are there any drawbacks? Is it difficult to configure?

Thanks in advance.

Paul

coopster

5:02 pm on Oct 5, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Well, I don't know that it is going to be any faster, let's put it that way. You are basically making a connection directly to the SMTP server as opposed to using a utility to queue and forward to the SMTP server. You may want to use a database to *queue* up emails and fire them out that way. jatar_k has more experience than I in this area, hopefully we can get a comment or two from him ...

Longhaired Genius

5:24 pm on Oct 5, 2005 (gmt 0)

10+ Year Member



It's best not to send your newsletter too quickly anyway. Some ISPs will delay or reject perfectly legitimate email if (they think) too many identical copies hit their servers in a short space of time. You can avoid this by sending in small batches, well spaced.

pniac

5:36 pm on Oct 5, 2005 (gmt 0)



Thanks again for the replies. I am also considering sending the whole batch at once, putting all addresses in the BCC field. I'd lose the option for an individual opt-out link, but I feel it might be worth it because it seems to be really a lot easier. Would this be a good option? Or would these be blocked too?

Longhaired Genius

5:38 pm on Oct 5, 2005 (gmt 0)

10+ Year Member



Why not use proper newsletter software? Dada Mail is free software and works well.

jatar_k

6:19 pm on Oct 5, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



as far as emails getting blocked there are a ton of reasons and more than one place that it can actually happen

I won't worry about actually getting it into inboxes as that isn't the specific issue here.

using a company/provider to send out newsletters is a good option though I am not sure that using a free service is a good option. I like having paid companies for things as it increases their accountability when something goes wrong. I always plan for something, at some time, to go wrong.

if you do it yourself then there are multiple options, 250 emails is minuscule, I doubt most ISP's would have an issue if they all went out at once. None of the ones I have worked with have had a problem at that number. I have found most often that I start having an issue as I near 500 though.

I sent out 25K (legitimate) emails not so long ago and I used a cron and a database to do it.

I added all emails to the db and had another column for 'sent' meaning the email had been sent already. I then had my cron run every 5 mins or so and select 50 emails where sent was still 'no' and fired off the emails and stopped. It took a few days but it worked very well. It was set up to send me a message when it was finished so that i could remove the cron. For your number it would only take five executions and you could stop it easily when it was complete.

I have also played around with various ways to send emails, the mail function ended up being the best. Straight injection into the mail queue was a bit faster but it still had the exact same problems with volume so there was no real advantage. It was also much harder to trap and handle failures.

I often use multiple logs to manage it, though that has to do with the very large volumes and multiple points of failure which you probably don't need to worry about. I worked in a dedicated environment and all the servers belonged to me, including the mail servers, that afforded us some advantages as well as creating a bunch of extra issues.

As far as the PEAR package goes I have never used it but I doubt it would be any faster, I can write straight to the mail queue with out it and it will have more overhead than my method so I can't see it being any faster than what I tested.

that help any?

pniac

10:39 pm on Oct 5, 2005 (gmt 0)



Yeah, that helped a lot, thanks!

I'm quite fond of the mail() function, so if possible I'd like to continue using it. Just a couple checks, to make sure:

1.
From what I understand from your story, you used the same mail() function to send 25,000 messages... correct?

2.
So the only problem would be that it takes too much time if you have a bunch, which can be solved by doing them at several smaller portions... correct?

3.
To send a portion, you just looped through fifty addresses, selected from your database, and for each you mailed the message using the mail-function, right?

surfin2u

12:04 am on Oct 6, 2005 (gmt 0)

10+ Year Member



I use mail() to send about 2000 emails at a time. I send them in batches of 100. I do this on a page that uses a form with a starting email id # in a text input box. I click on the submit button and 100 emails are sent and the starting email id # in the text input is increased by 100. I just click on submit again to send the next 100.

pniac

12:48 pm on Oct 6, 2005 (gmt 0)



For each individual address you use the mail() command, right?

I now think of doing something like:

do {

mail(user, message, etc.)

} while (database_loop)

And then only like 50 addresses at once... that's the same as how you guys do it, right?

surfin2u

1:56 pm on Oct 6, 2005 (gmt 0)

10+ Year Member



Yes, that's pretty much it. The only special twist that I add is to add an id number for the person receiving the email to links in the email, so that when they click on a link to a page on my site, I can tell who they are.

jatar_k

3:49 pm on Oct 6, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



1. correct
2. correct
3. correct

the only added piece is I update my sending table to be 'sent' if the email gets sent. When that particular mailout is done and the cron has been turned off I reset them all to no

this means that my query on who to send to looks something like

select email from emailout where sent='no' limit 50

then as my loop runs
i build the email itself
send the email using the mail function
update the row
update emailout set sent='yes' where email = $email

something like that

what you put in the email and how that is done is another story all together. Always fun trying to get emails past junk/spam filters

pniac

4:37 pm on Oct 6, 2005 (gmt 0)



Perfect, all clear to me now. I'll go for the mail function, sending them in small portions.

Thanks for all the replies people!

dcrombie

4:46 pm on Oct 6, 2005 (gmt 0)



One of our sites sends a weekly mailout to approx 5,000 addresses in blocks of 500 using mail(). The only extra step I take is to first sort the addresses by domain so that sendmail can 'bulk send' those from the same domain.