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?

Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
Paul Wicks
  • 62,960
  • 55
  • 119
  • 146
  • 1
    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. – James John McGuire 'Jahmic' Aug 26 '15 at 11:20
  • 6
    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? – obe Aug 05 '17 at 17:07
  • If you check on github, you will see 7K stars for SwiftMailer and on top in php section – flik Dec 28 '18 at 10:48
  • and PHPMailer has more than 12K stars on github – flik Dec 28 '18 at 12:13
  • PHPMailer can use `mail()` function. SwiftMailer cannot use `mail()` function while `mail()` function is still supported by PHP. See more at https://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. https://github.com/PHPMailer/PHPMailer https://github.com/swiftmailer/swiftmailer – vee Aug 05 '19 at 06:39

7 Answers7

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.

Darryl Hein
  • 142,451
  • 95
  • 218
  • 261
benlumley
  • 11,370
  • 2
  • 40
  • 39
  • 3
    PHPMailer has moved to GitHub now. New Link https://github.com/Synchro/PHPMailer – Dracs May 01 '13 at 06:54
  • 13
    To be clear (I'm the maintainer), PHPMailer does now live [on github](https://github.com/PHPMailer/PHPMailer) at the address in this answer, not the old sourceforge, google code repos, or my personal fork (Synchro). – Synchro Feb 24 '15 at 22:51
33

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)

M A Hossain Tonu
  • 1,437
  • 15
  • 14
  • 5
    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. – M A Hossain Tonu Jun 09 '14 at 16:00
  • 9
    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...? – Steve Chambers Aug 26 '14 at 20:42
  • 11
    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 yours – M A Hossain Tonu Aug 27 '14 at 06:31
  • 10
    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. – iquito Sep 24 '16 at 14:20
  • 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. – M A Hossain Tonu Mar 01 '18 at 14:07
  • 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. – M A Hossain Tonu Mar 01 '18 at 14:07
9

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

troelskn
  • 115,121
  • 27
  • 131
  • 155
  • 9
    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. – Marco Demaio Dec 19 '11 at 18:51
  • 1
    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. – MaxiWheat May 02 '14 at 16:49
  • 1
    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. – divix Jan 25 '16 at 08:48
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.

Sheldmandu
  • 1,700
  • 16
  • 10
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

halfer
  • 19,824
  • 17
  • 99
  • 186
Marco Demaio
  • 33,578
  • 33
  • 128
  • 159
  • Most of the above PHPMailer links are obsolete - you should now [start here](https://github.com/PHPMailer/PHPMailer). – Synchro Feb 24 '15 at 22:42
  • @Synchro: I updated the links, next time feel free to edit my answer and fix it by yourself. – Marco Demaio Feb 25 '15 at 12:35
  • 2
    > 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. – MrMesees Jan 13 '17 at 12:21
  • 1
    @MrMesees: well stepping through execution flow by looking into hundreds of micro files is more time consuming than looking at few bigger files. :) – Marco Demaio Feb 10 '17 at 13:19
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.

daremon
  • 4,894
  • 2
  • 27
  • 27
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.

user398341
  • 6,339
  • 17
  • 57
  • 75