Viewed   219 times

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?



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

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.

Saturday, December 3, 2022

You need to use $this->email->clear(); to clean out the variables set within the loop. Read the manual.

Tuesday, August 9, 2022

Swiftmailer is more concerned with sending email (e.g. from your script to an SMTP server which handles the delivery). Swiftmailer has no capacity for receiving emails, which is what a bounce is.

The only time Swift could catch a bounce is if the SMTP server it's handing the email off to rejects the email outright. Otherwise, once it's queued in the SMTP server, Swiftmailer's done with it.

In real world terms, Swiftmailer is you walking a letter down the the mailbox. If the mailbox is welded shut, Swiftmailer will tell you, but otherwise the letter goes into the mailbox and then Swift's done.

A bounce is a letter carrier coming by the next day to drop off the envelope with 'return to sender' stamped on it. Swift has nothing to do with this, as it doesn't RECEIVE emails, it only walks them from your house to the mailbox.

Sunday, August 21, 2022

I've used PHPMailer for my projects and have no complaints about it. Haven't used Swiftmailer, but both seem to be pretty much the same in terms of usage and usefulness, differing only in implementation details. When you get right down to it, they're both just friendly interfaces to hide the details of SMTP email from you.

Pick whichever one whose style suits you best and go with it.

Tuesday, December 20, 2022

There's an addStringAttachment() method that seems to fit your need:


addStringAttachment(string $string, string $filename, string $encoding = self::ENCODING_BASE64, string $type = '', string $disposition = 'attachment') : boolean

Add a string or binary attachment (non-filesystem).

This method can be used to attach ascii or binary data, such as a BLOB record from a database.

Monday, November 21, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :