I get error when trying send mail with Yii::$app->mailer->compose() function. This error appears when trying to connect smtp server, so I provide error message and mailer YII2 configuration
Expected response code 250 but got code "535", with message "535-5.7.8
Username and Password not accepted.
Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials 59sm3639427wrc.23 -> gsmtp"
Here is params from config/common.php file:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'port' => '587',
'encryption' => 'tls',
'username' => 'myemailbox#yahoo.com',
'password' => 'myemailpass',
'host' => 'smtp.mail.yahoo.com',
],
],
I already enabled "Allow apps that use less secure sign in" function in Yahoo account settings. Trying "app password" option but got the same result.
Before using yahoo smtp I tried it the same way with google smtp. Error message still refers to the https://support.google.com page. Is it possible Apache cached login and pass to smtp server?
Of course I checked google support page and followed instructions included https://accounts.google.com/DisplayUnlockCaptcha page.
try changing port
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'port' => '465',
'encryption' => 'tls',
'username' => 'myemailbox#yahoo.com',
'password' => 'myemailpass',
'host' => 'smtp.mail.yahoo.com',
],
],
I resolved this case, but didn`t detect what exactly was the cause. Maybe there was some sort of cache of config error.
So I put this direct setting right before compose function:
\Yii::$app->mailer->setTransport([
'class' => 'Swift_SmtpTransport',
'port' => '587',
'encryption' => 'tls',
'username' => 'myemailbox#yahoo.com',
'password' => 'myemailpass',
'host' => 'smtp.mail.yahoo.com',
]);
And it started to work.
Related
It seems 1and1 web hosting service only allows plain PHP mail to send mail. But now Swiftmailer has thrown Swift_MailTransport away, so I'm unable to get simple PHP mail sending functionality using that class:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_MailTransport', // NOT WORKING ANYMORE!!!
],
]
Is there any other class apart from yii\swiftmailer\Mailer I might use to accomplish this task?
The entire mail transport is deprecated. Use sendmail or smtp
https://www.yiiframework.com/wiki/656/how-to-send-emails-using-smtp
'mail' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'localhost', // e.g. smtp.mandrillapp.com or smtp.gmail.com
'username' => 'username',
'password' => 'password',
'port' => '587', // Port 25 is a very common port too
'encryption' => 'tls', // It is often used, check your provider or mail server specs
],
],
I'm trying to send an email using yii2 mailer component.
config web.php
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
// 'useFileTransport' => true,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'myEmail2131#gmail.com',
'password' => 'password1234',
'port' => '587',
'encryption' => 'tls',
]
],
And my code.
Yii::$app->mailer->compose()
->setFrom('myEmail07#gmail.com')
->setTo('toSomeone#gmail.com')
->setSubject('Some Subject here')
->setTextBody('Plain text content')
->setHtmlBody("<p> This is the body of email</p>")
->send()
I'm getting this error.
Swift_TransportException Expected response code 250 but got code
"535", with message "535-5.7.8 Username and Password not accepted.
Learn more at 535 5.7.8
https://support.google.com/mail/?p=BadCredentials
a13-v6sm4133042wrc.19 - gsmtp "
I already configure my Gmail account as said here enter link description here
less secure app on on your gmail account
And I also try to use ssl instead tls.
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
// 'useFileTransport' => true,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'myEmail2131#gmail.com',
'password' => 'password1234',
'port' => '465',
'encryption' => 'ssl',
]
],
Any idea? Thanks!
I've found a solution.
Note: I use this method just for testing. soon on production, I will use an actual email of our company.
My mail config
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
// 'useFileTransport' => true,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'myEmail2131#gmail.com',
'password' => 'password1234',
'port' => '587',
'encryption' => 'tls',
]
],
Then do this:
https://www.google.com/settings/security/lesssecureapps and active it.
https://accounts.google.com/b/0/DisplayUnlockCaptcha and active it.
As answer from Ankit Tyagi here
I am working on yii2. Using my localhost on XAMP I am trying to send an email. While sending the email I am getting the bellow error in POSTMAN.
"name": "Exception",
"message": "Connection could not be established with host smtp.gmail.com [ #0]",
"code": 0,
"type": "Swift_TransportException",
Bellow is my common/config/main-local
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'transport'=>[
'class'=>'Swift_SmtpTransport',
'host'=>'smtp.gmail.com',
'username'=>'MY GMAIL ID',
'password'=>'Password',
'port'=>'465', //587 also tried this with ssl and tls
'encryption'=>'ssl' //tls also tried with port 465,26 and 587
],
'viewPath' => '#common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
//'useFileTransport' => false,
],
Below is my sending request
Yii::$app->mailer->compose()
->setFrom('MY ID')
->setTo('SEND ID')
->setSubject('New Message')
->setTextBody('HI')
->setHtmlBody('<b>HTML content</b>')
->send();
I have searched each and every question(s) but couldn't able to solve the issue. What should I do now ?
Any help would be highly appreciated.
Make sure you have enabled less secure apps for your account first.
Then you should use the following settings for port:587 and encryption:tls and it will work, I use these setting for my local computer at home to send emails from localhost.
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'transport'=>[
'class'=>'Swift_SmtpTransport',
'host'=>'smtp.gmail.com',
'username'=>'MY GMAIL ID',
'password'=>'Password',
'port' => '587' ,
'encryption' => 'tls' ,
],
'viewPath' => '#common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
//'useFileTransport' => false,
],
The comment of Muhammad is helpful. I don't have enough reputation to add this comment to his post.
After enabling access to less secure apps on gmail, WAIT for some time for the change to take effect, otherwise, you will continue to get errors about 'TLS not available' as it happened to me.
To put everything together,
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'xxxx#gmail.com',
'password' => 'your password',
'port' => '587',
'encryption' => 'tls',
'streamOptions' => [ 'ssl' => [ 'allow_self_signed' => true, 'verify_peer' => false, 'verify_peer_name' => false, ], ]
],
'viewPath' => '#common/mail',
],
* IMPORTANT *
Disabling SSL verification has security implications. Without verification of the authenticity of SSL/HTTPS connections, a malicious attacker can impersonate a trusted endpoint (such as GitHub or some other remote Git host), and you'll be vulnerable to a Man-in-the-Middle Attack. Be sure you fully understand the security issues before using this as a solution.
Make sure you have enabled less secure apps for your account first
Check Gmail through other email platforms
Edit \common\config\main-local.php
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'yourname#gmail.com',
'password' => 'yourpass',
'port' => '587',
'encryption' => 'tls',
'streamOptions' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],
],
],
I am using swift mailer in yii2, i am using correct smtp setting still not able to send email.
I got this error - Failed to authenticate on SMTP server with username "example#example.com" using 2 possible authenticators
my swift mailer settings are:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'myHostName',
'username' => 'myUsername',
'password' => 'myPassword',
'port' => '465',
'encryption' => 'ssl',
],
],
I searched a lot on internet but found no solution, some people suggested that it would work by making 'useFileTransport' => false, but it is still not working.
I have a error with yii2, I can't send emails via yii with a email account. If my password is correct :(
This is my code:
web.php
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'user#hya.com.mx',
'password' => 'passwd',
'port' => '587',
'encryption' => 'tls',
],
],
'log'
Controller.php
Yii::$app -> mailer -> compose()
-> setFrom('users#hya.com.mx')
-> setTo('jhon#hya.com.mx')
-> setSubject('Test')
-> setTextBody('Plain text content')
-> setHtmlBody('It is a test')
-> send();
It looks like you are using Google SMTP server. Google has a new security check that only allows you to send emails from google apps. If you are using any other you will run into such errors. To fix this you can do as follows:
Use default sendmail function by having
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
],
I find the first solution more efficient
Change google setting to allow less secure apps
Follow this link to change you gmail settion https://myaccount.google.com/security
I use the following configuration and work right
is pratically equals to yours but with a difference the username is google mail user and not an noyt google app user
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
//'useFileTransport' => true,
'useFileTransport' => false,//set this property to false to send mails to real email addresses
//comment the following array to send mail using php's mail function
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'myname#gmail.com',
'password' => 'mypassword',
'port' => '587',
'encryption' => 'tls',
],
],
hope is useful