I need to create a PHP class that would send e-mails to all members of the website. Simple mysql_fetch_array and loop doesn’t fit because my client wants a class and I actually don’t know much about classes and what he exactly wants. Can you explain or give me any hints?
Share
Well in general, we can’t tell you what your client wants. You’ll have to ask him. 🙂 But a few general pointers on sending out bigger numbers of E-Mails.
When putting together an E-Mail class, the most sensitive thing to be aware of, and the most likely reason for it not working, is the number of mails to be sent.
mail()is a very slow command for sending mails, and if you have thousands of members, a puremail()solution is likely to fail, because the run time of a PHP script is usually limited to 30 or 60 seconds.Check out E-Mailing classes like PHPMailer that can send directly through SMTP, which is way faster.
Also be sure to check out whether the server the mails are sent from has any limit imposed on the number of outgoing E-Mails per interval. If you are using a hosting provider, talk to them first. This is also good because then they know you’re not misusing their servers for spam.
Be sure to do test runs before actually starting the sending out to actual members.
Also make sure your outgoing E-Mails look o.k. technically so they don’t get spam filtered. See this question for a few pointers.
For basics on Object Oriented Programming, see e.g. the PHP Manual on the subject.
Generally, be very careful when working on a mailing system. Make sure you have checks in place that prevent actual sending to actual members before everything is in order. Imagine how embarrassing it is to have ten “asfsafsd” test E-Mails sent out to each person on the recipient list.
Don’t forget that there are paid services available that do this as well. If there is some budget involved, and you would like to use an existing paid solution rather than do it yourself, you can set up another question here on SO.