PhpMailer vs. SwiftMailer? [closed]
Asked Answered
G

7

65

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?

Gilstrap answered 19/11, 2008 at 23:23 Comment(5)
Answers are, indeed, a bit opinion oriented, but well thought out opinions, and I have found valuable, as I make a similar decision. By the number of upvotes, it seems others have found this valuable also.Clevelandclevenger
Half of the stuff most useful for me on SO is "off-topic". On many of these "closed as off-topic" questions I can see "it's off-topic but it helped me" kind of comments. Maybe instead of seeing five different moderators jump on a question to shut it down, we can see them vote for changing this policy? How is this question more deserving to be closed than 98% of the questions posted on SO, that are like "what is wrong with this code?" or about how to achieve some extremely specific task that would never be relevant to anyone else?Vann
If you check on github, you will see 7K stars for SwiftMailer and on top in php sectionRavelin
and PHPMailer has more than 12K stars on githubRavelin
PHPMailer can use mail() function. SwiftMailer cannot use mail() function while mail() function is still supported by PHP. See more at github.com/swiftmailer/swiftmailer/issues/866 PHPMailer have more forked, starred watched than SwiftMailer. PHPMailer have 1361 issue closed, 35 opened. SwiftMailer have 558 issue closed, 200 opened. github.com/PHPMailer/PHPMailer github.com/swiftmailer/swiftmailerSweetscented
K
56

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.

Kinase answered 20/11, 2008 at 0:2 Comment(2)
PHPMailer has moved to GitHub now. New Link github.com/Synchro/PHPMailerWristband
To be clear (I'm the maintainer), PHPMailer does now live on github at the address in this answer, not the old sourceforge, google code repos, or my personal fork (Synchro).Stepdame
C
34

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)

Chromogenic answered 8/6, 2014 at 20:22 Comment(6)
May I know why I got a down vote? There are big differences in licensing when we want to use one of'em for our distributable project.Chromogenic
IMO the anonymous down vote seems unfounded - this is a good point. But think the post would be more valuable if you could perhaps point out any important differences between the two licenses...?Jockey
Someone's upvote clears that :) Anyway the major differences between the two licenses are as: LGPL is "infectuous", which means if you use it, you risk having to (L)GPL your own work too. GPL (and, depending on the circumstances, LGPL as well) practically excludes usage in a closed-source project. MIT is the "Can do Anything" license, do what you want with my code excepted pretend that the code is yoursChromogenic
The comment from M A Hossain Tonu about the LGPL being "infectuous" is completely wrong. The difference between GPL and LGPL is exactly that: GPL is a strong copyleft license, meaning all your code must be changed to a GPL-compatible license too, whereas LGPL only includes a copyleft part for the code in the distributed library, so not your application code. For a library like PHPMailer LGPL is completely fine and irrelevant to your own code, which is not affected at all by this license.Westmorland
Of course, LGPL is less restrictive than the GPL origins (also hinted in its name: Lesser GPL). While the GPL license requires you to share the code of all “derivative work”, the LGPL requires you to share only the source code of the work “based” on the LGPL-licenses components and not of the work which ‘uses’ it, meaning you are not obligated to share the code that is designed to work with the library by being complied or linked with it - static or dynamic.Chromogenic
Hence, considering the derivative works from PHPMailer, “infectuous” word used to describe the point of sharing your code component if it is “based” on LGPL licensed components. In general purpose, you are not deriving work from PHPMailer, so it absolutely fine and take the license headache out.Chromogenic
C
9

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

Craw answered 19/11, 2008 at 23:36 Comment(3)
It doesn't seem you can use it on its own, I think you need to use the entire zend library which is more than 6 MB compressed in the minimal version.Eneidaenema
Zend_Mail works great, but yes, requiring the whole framework is kind of a dowside for small projects if you don't use Zend Framework.Oubre
ZF Mail doesn't require you whole of the 6mb framework. One of the best features of Zend Framework is that you can use only classes which you need. However you will still need like 10-20 files to include from Zend.Decrypt
C
8

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.

Chilson answered 8/1, 2011 at 12:42 Comment(1)
This thread may also be useful: forums.phplist.com/viewtopic.php?t=8270Jockey
I
6

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.

Iodometry answered 20/11, 2008 at 0:2 Comment(0)
E
6

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

Eneidaenema answered 25/2, 2013 at 19:1 Comment(4)
Most of the above PHPMailer links are obsolete - you should now start here.Stepdame
@Synchro: I updated the links, next time feel free to edit my answer and fix it by yourself.Eneidaenema
> SwiftMailer is made by hundreds of small files that make SwiftMailer more difficult to debug compared to the 3 files PHPMailer is made of. Terrible reasoning. number of files should not be a deciding factor on using a library or debugging as debugging does not involve fiddling with files, it involves stepping through execution flow.Backus
@MrMesees: well stepping through execution flow by looking into hundreds of micro files is more time consuming than looking at few bigger files. :)Eneidaenema
R
4

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.

Rugging answered 15/6, 2011 at 20:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.