Question

I'm building a fairly simple PHP script that will need to send some emails with attachments. I've found these 2 libraries to do this.

Does either one have significant advantages over the other? Or should I just pick one at random and be done with it?

Was it helpful?

Solution

I was going to say that PHPMailer is no longer developed, and Swift Mailer is. But when I googled ...

https://github.com/PHPMailer/PHPMailer

That suggests its being worked on again.

I've used PHPMailer a lot, and its always been solid and reliable. I had recently started using Swift Mailer, for the above reason, and it too has given me no trouble.

Now that PHPMailer is developed again, I think I'll probably give the new version a try.

So, my answer is that both are capable, and that it doesn't matter that much – choose one, learn it, use it. Both offer massive advantages over mail() and abstract away the nuances of email so that you can get on with whatever you are really trying to develop.

OTHER TIPS

Whatever the features are, they have variety in their applicable licenses:

PHPMailer - LGPL 2.1 (https://github.com/PHPMailer/PHPMailer)

SwiftMailer - MIT license (https://github.com/swiftmailer/swiftmailer)

There is also Zend_Mail. If I had to pick one for a new project today, I would seriously consider that.

Having looked at both I think SwiftMailer has a much nicer interface than PHPMailer and as someone has pointed out Zend_Mail is also another good option especially if you're using other Zend components. It makes life much easier if you use everything from the same framework.

I've used PHPMailer on many projects and never had a problem. It's feature complete and it has good docs.

I had never heard of Swiftmailer so I took a peek at the website. It seems a nice solution too.

If your needs are simple as you say, then just pick one at random.

Google trends: swiftmailer is growing but phpmailer is still very strong.

I would go with Swiftmailer because documentation is clear and easy. Phpmailer site/docs are a bit messy (at least they look so).


EDIT: after trying them both (and banging my head against an hosting issue for which SwiftMailer did not output any type of hint) I completely changed my mind, I would definitely go with PHPMailer for at least one good reason: it's much easier to debug in the event you have any issue.

Both SwiftMailer and PHPMailer provide debug options (SwiftMailer with a plugin and PHPMailer by turning on SMTPDebug = 2), but SwiftMailer is made by hundreds of small files that make SwiftMailer more difficult to debug compared to the 3 files PHPMailer is made of.

And about docs, the PHPmailer documentation is less fancy looking, but it has got all you need: simple tutorial, examples

I've just switched to Swift today due to the problems with PHPMailer and PHP 5.3 - even the latest version - which is a shame. Swift has a very well documented integration, which makes things easier.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top