Swift_TransportException: Failed to authenticate on SMTP server on 000webhostapp.com - php

In trying to send email using SwiftMailer.
$app['swiftmailer.options'] = array(
'host' => 'smtp.gmail.com',
'port' => '465',
'username' => 'mymail#gmail.com',
'password' => 'mypassword',
'encryption' => 'ssl',
'auth_mode' => 'login'
);
$message = (new Swift_Message('Title'))
->setFrom(array('mymail#gmail.com'))
->setTo(array($mail_to))
->setBody($text);
$app['mailer']->send($message);
This configuration works on my local virtual host. But when I deployed my application on 000webhost.com I get an exception.
Uncaught Swift_TransportException: Failed to authenticate on SMTP
server with username "mymail#gmail.com" using 1 possible
authenticators in
/storage/ssd5/070/4187070/public_html/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/AuthHandler.php:181
I didn't find any solutions for troubles on hosting services. Also I allowed access from unknown applications on gmail settings and visited DisplayUnlockCaptcha. That didn't help me
Maybe something wrong with the hosting service. Please help me to solve this problem!

Related

LARAVEL 9. ERROR LARAVEL EMAIL: Unable to connect with STARTTLS: stream_socket_enable_crypto(): SSL operation failed with code 1

Greetings to the community!
I have recently developed a web page with Laravel 9.X, which works correctly in local, but when I upload it to my Host, I am having problems with sending emails.
When I have been testing locally, it has been working correctly, and I have been using mailtrap. Now that I have uploaded it to the server, I have my own SMTP, and it is not working for me. I have the ssl certificate created, but there is no way it will send me any mail. I get the following error:
Unable to connect with STARTTLS: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed.
SSL working fine when i visit the site with https.
I have configured my .env file, where I have put:
HOST: my smtp server; PORT: 587; ENCRYPTION TYPE: SSL; USERNAME AND PASSWORD: Those of my email account.
I have been touching also my file located in config/mail.php, putting the same configuration as in the .env file. I have also tried with other ports like 25, 465... among others.
I have tried to access the mail account from outlook, using the IMAP protocol, and I have been able to connect correctly, so the mail can be accessed.
I have checked lot of things in Google, and also every blogs y found in Stack Overflow, but nothing worked.
Any idea what is going on?
Am I missing something to configure?
I had this problem after upgrading to the new 9 version, so you need to follow two steps.
Edit your .env file located in the root of the project The place where your mail settings are described, change tls to null. If you do not have such a line, then add
MAIL_ENCRYPTION=null
If you have version 8 then this will be enough, but in version Laravel 9 you will need to open the file app/config/mail.php Find a section mailers smtp add two options 'auth_mode' => null and 'verify_peer' => false an example of how it would look
'mailers' => [
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => null,
'verify_peer' => false,
],

Using gmail smtp via Laravel: [Connection timed out #110]

I know this question is asked many times and have different solutions and I have tried all but no one has worked. This is my settings.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=abc#mydomain.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=ssl
And application is currently running on Centos 7 OS.
I always get
Swift_TransportException in StreamBuffer.php line 269: Connection could not be established with host smtp.gmail.com [Connection timed out #110]
at Swift_Transport_StreamBuffer->initialize(array('protocol' => 'ssl', 'host' => 'smtp.gmail.com', 'port' => '465', 'timeout' => '30', 'blocking' => '1', 'tls' => false, 'type' => '1', 'stream_context_options' => array())) in AbstractSmtpTransport.php line 113
I have tried all solutions, by Replacing: smtp.gmail.com with 173.194.65.108, or replacing smtp.gmail.com by gmail-smtp-msa.l.google.com. When I do these two steps, it got server not found error.
If I change mail driver from smtp to sendmail or mail, no error is thrown but no email is sent.
If I use ip address of smtp.gmail.com, I got same result. If I change port from 465 to 587 and encryption from ssl to tls, nothing happens.
I have also created a file in etc/gai.conf and put precedence ::ffff:0:0/96 100. It worked one time. But later after two hours, it stopped working and started throwing same error.
I have also tried using my gmail id but all in vain.
The only solution that I couldn't be able to test is verifying httpd_can_sendmail as whenever I run command getsebool httpd_can_sendmail I get getsebool: SELinux is disabled. Is this the problem or is there any other way to get it fixed?
Here is my working mail config file:
return [
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => ['address' => '*******#gmail.com', 'name' => '****'],
'encryption' => 'tls',
'username' => '*******#gmail.com',
'password' => '*******',
'sendmail' => '/usr/sbin/sendmail -bs',
];
but from your question i can see you already tried all this, so i can assume it is a network problem based on error 'connection time out', what i mean is that something is blocking your connection, it might be your firewall if you have.
so first you should check that the port 587 is open, or you can check if other application can connect with smtp.gmail.com (don't know how to do it in centOs).
And at last this might not be a problem but you have to enable 'Allow less secure apps' in your google account just for testing. (This is not permanent solution but for testing, if it works then you should enable two step verification in google account and then create new application, you can create new special password which you can use as your password for smtp server)
In my case it was necessary to clear config cache to pull up .env file new settings
php artisan config:cache
Since you are using gmail, but I don't know what password you are setting, the MAIL_PASSWORD variable must be the same as the gmail application password. In this case, Gmail provides a third-party application service so that these, (in this case your application), can send emails using this type of authentication.

Sending Mail via SMTP on Japan ISP

I have this weird problem. I have setup my PHP app to send email to users, for now it is using gmail. There is no problem sending mail from my machine. But when my colleague in Japan tried my app, it doesn't send the mail. In the logs, it says that the app failed to authenticate.
'driver' => 'smtp',
'smtp' => array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'test.email#gmail.com',
'password' => 'password',
'timeout' => 5,
),
'newline' => "\r\n"
He is running the app in his machine, not from a remote server.
Google might have blocked your login because it was deemed as suspicious. (https://support.google.com/accounts/answer/6063333?hl=en)
You might want to login to this account and navigate to https://security.google.com/settings/security/activity and allow blocked device to continue.

Failed to authenticate on SMTP server with username using 2 possible authenticators

I've configured to gmail SMTP server to send email. Account less secure app turned ON, also Recapture thing enabled. Here is the mail.php configuration.
This code working fine on hostgator server. But we have another server, mails are not sending from that server. What should I do now?
Error image
http://screencast.com/t/BSCurEEubPJV
return array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => array('address' => 'xxx#gmail.com', 'name' => 'xxxxTeam'),
'encryption' => 'tls',
'username' => 'xxx#gmail.com',
'password' => 'xx#123',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
I got the same issue. Finally found that my server IP address was blacklisted.
Please check your IP address using this link.
Link : https://mxtoolbox.com/blacklists.aspx
If it is blacklisted, send re-list request via they provide links. That's it
Thank you

Swift_TransportException Failed to authenticate on SMTP server with username email#domain.com using 2 possible authenticators on shared host

I'm develop a website using Laravel 4.1. I config my email system and send email successfully on built-in server localhost:8000. But when I host the web on a shared hosting, it always tell: Swift_TransportException
Failed to authenticate on SMTP server with username "email#domain.com" using 2 possible authenticators
I don't know what the reason is? I've search on this site but no solution works.
return array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => array('address' => 'email#gmail.com', 'name' => 'Test email'),
'encryption' => 'ssl',
'username' => 'your_gmail_username',
'password' => 'your_gmail_password',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
I also used my our domain's email but it doesn't work neither. Hope for help.
In my case, I had a Cpanel dedicated server. My host informed me that exim mail server was failing and restarting a couple times a day.
It looked like all connection threads were being used up and then locked until it restarts.
My host added another 100 connection threads to the pool. Most probably this help you as well.

Categories