A more flexible way to send emails in PHP

I want to integrate some email functionality into my system, and I'm not too impressed with the use mail()

for sending emails as the feature is pretty limited in what it can do.

Ideally, I need an infrastructure or something that I can integrate into my system that allows me to generate messages in my own way and then send them.

A few other features that would be very nice:

  • Queuing system, so emails can be throttled well and simply.
  • Lightweight with minimal dependencies
  • Supports plain and html email, as well as any number of attachments.
+2


source to share


2 answers


Like most of the holes in core PHP functionality, one is to fill it with the Zend Framework class. Zend Framework lets you pick and choose which parts you use, so dependencies will be minimal. Zend_Mail looks like it will handle your plain text / html / attachment.



As far as the queuing system is concerned, this is only an opinion, but it is not really PHP's job. If you get to the point that the message is serious enough for you to consider throttling, you will want to familiarize yourself with sendmail, postfix, or whatever mail agent (MTA) you use. Almost all PHP classes that exchange mail actually just send a message to the MTA for processing. Any system that implements throttling in PHP is (most likely) just going to throttle sending it from the MTA, and the MTA is still a point of failure.

+3


source


Most frameworks have their own Mail objects that can be used to create messages.

I personally like Zend_Mail as it is part of Zend Framework, which is loosely coupled, so it can be used internally or used as a standalone.

You can read more about this here: http://framework.zend.com/manual/en/zend.mail.html



This definitely meets your second and third requirements. I don’t think it will work for all three requirements, because your first requirement for a queuing system will require tight integration with the server.

If you are looking for something to queue messages, you may need a newsletter system, but I have not found a good open source PHP code.

+3


source







All Articles