PhpMailer vs. SwiftMailer?
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.
Should I use PHPMailer or SwiftMailer?
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.
Cannot send mail using PHPmailer or swift mailer
For gmail the SMTP server (Host
field) should be smtp.gmail.com
.
Difference between Laravel Mail vs swiftmailer
Laravel provides a clean, simple API over the popular SwiftMailer library.
And about the php mail:
If you wish to use the PHP mail function to send mail, you may change the driver to mail in the configuration file.
Mail::send is just a laravel wrapper for swift mailer, so you are calling swift mailer when doing that call unless you change 'driver' => 'smtp'
to 'driver' => 'mail'
, only then will it use the PHP's mail.
Reference: Laravel Mail Documentation
I cannot send mail with SwiftMailer or PHPMailer from Localhost using gmail
I have been able to overcome the problem, at least with SwiftMailer
. The solution must have arisen after my PHP upgrade from 5.2.5 to 5.6, which is the version I have currently. The insight came from this page:
https://github.com/swiftmailer/swiftmailer/issues/544
If you are using PHP 5.6, the error does occur because of the "SSL
context options" used for the stream context in swiftmailer. IN PHP
5.6 verify_peer and verify_peer_name the default was set to TRUE, so PHP checks the SSL certificate. It is currently not possible to
disable it in swiftmailer using some options.You could disable the SSL check by modifying the function
"_establishSocketConnection" in StreamBuffer.php. Add these lines
before stream_socket_client command:
$options['ssl']['verify_peer'] = FALSE;
$options['ssl']['verify_peer_name'] = FALSE;
It would be great if these options could be set without hacking the
code.
Thanks to https://stackoverflow.com/a/29448735/2554788 who first pointed me to the said post.
By the way, the path to StreamBuffer.php
is:
\lib\classes\Swift\Transport
A word of warning though: this solution is based on hacking the code inside a class, and will probably fail, say, after upgrading SwiftMailer
versions (in which case you'd need to go back and hack the code again).
Perhaps, more current versions of SwiftMailer
have put their acts together in PHP 5.6 (I use SwiftMailer 5.1 currently). I intend to try an upgrade ASAP, hoping there has been an elegant fix for this issue.
SwiftMailer force SMTPAuth like PHPMailer
https://stackoverflow.com/a/48933513/10283047 deals with sending mail in Java, but the basic problem seemed to be the same here:
If you connect via port 587 you initially start a plain connection where you have to start TLS by explicitly sending the STARTTLS-command. You have to tell JavaMail to do that, otherwise it will try to proceed unsecured. The SMTP-server doesn't send any authentication-mechanism-informations unless the TLS-connection is established, so JavaMail is assuming that no authentication is needed and tries to send the mail without.
So it appears you need to explicitly specify that you want this to be an encrypted connection here as well.
The third parameter for the Swift_SmtpTransport constructor does that, supply either 'ssl' or 'tls':
new Swift_SmtpTransport('smtp.example.org', 587, 'ssl'); // or
new Swift_SmtpTransport('smtp.example.org', 587, 'tls');
With the phpMailer version you had $data->SMTPSecure take care of that part.
PHPMailer/SwiftMailer Send Email - Connection could not be established with host smtp.gmail.com
Right at this moment, gmail smtp servers appear to be having widespread outages this morning. I don't know code:) but was searching for others having issues. Re-try later.
Related Topics
Using PHP'S Swiftmailer With Gmail
How to Make a PHP Form That Submits to Self
Can File Uploads Time Out in PHP
How to Emulate a Get Request Exactly Like a Web Browser
How to Store File Name in Database, With Other Info While Uploading Image to Server Using PHP
How to Best Store User Information and User Login and Password
PHP - Redirect and Send Data Via Post
PHP-Intl Installation on Xampp
Interpolation (Double Quoted String) of Associative Arrays in PHP
How to Sort a Multidimensional Array by One of the Fields of the Inner Array in PHP
In Where Shall I Use Isset() and !Empty()
Serializing PHP Object to Json
Get in Woocommerce Cart the Product Id of a Cart Item
Explode String into Array With No Empty Elements
MySQLi_Fetch_Array While Loop Columns