While sending email from my website emails delivered to gmail accounts but Emails not deliver to Hotmail account, i am using yii2 swift mailer configuration in yii2 config file
`mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'mail.sample.in',
'username' => 'develop#sample.in',
'password' => 'dev98761XXX',
'port' => '25',
'encryption' => 'tls',
],
],
Related
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 use Windows and Yii 2.0.13.1 and xampp with php7.1.4.
When logging in, I click on reset it link and i'm entering my email and send, I encounter this error:
Swift_TransportException
Process could not be started [The system cannot find the path specified.
]
My common/config/main-local.php is:
'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' => false,
],
Other settings and files are in the default mode.
what is the problem? Please guide me
Seems that in your config is missing the transport config
eg: using gmail.com as transport (you should choose the trasport available for your host)
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
'useFileTransport' => false,//set this property to false to send mails to real email addresses
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'yourmail#gmail.com',
'password' => 'your_password',
'port' => '587',
'encryption' => 'tls',
'streamOptions' => [
'ssl' => [
'verify_peer' => false,
'allow_self_signed' => true
],
]
],
],
Everything is right now
I tried to do some changes in common/config/main-local.php
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.mailtrap.io',
'username' => 'example#examplemail.com',
'password' => '***************',
'port' => '2525',
'encryption' => 'tls',
],
],
Maybe some of your transport settings are incorrect, so it cannot send an email. For local server you can just set useFileTransport to true like:
'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,
],
Then check your <app>/runtime/mail/folder, where *.eml mail will be generated. Therefore you can click on your password-recovery link and proceed futher.
P.S. Yii2 advanced template includes email password-recovery feature from the box (if you are implementing it from scratch)
I want to send the email from different email accounts to users.
How I can configure multiple $mailer components?
Here is what I have implemented currently in main-local.php
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport'=>false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'xxxxxxxxx',
'password' => 'yyyyyyyyyy',
'port' => '465',
'encryption' => 'ssl',
]
],
Have you tried this?
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport'=>false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'xxxxxxxxx',
'password' => 'yyyyyyyyyy',
'port' => '465',
'encryption' => 'ssl',
]
],
'mailerb' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport'=>false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'xxxxxxxxx',
'password' => 'yyyyyyyyyy',
'port' => '465',
'encryption' => 'ssl',
]
],
Access:
Yii::$app->mailer->compose()
Yii::$app->mailerb->compose()
To use Mailer, you should configure it in the application configuration like you just did in main-local.php
To send an email, you may use the following code:
Yii::$app->mailer->compose('contact/html', ['contactForm' => $form])
->setFrom('from#domain.com')
->setTo($form->email)
->setSubject($form->subject)
->send();
Where in:
->setFrom(array('mail1#gmail.com' => 'NAME','mail2#gmail.com' => 'NAME2'))
You may pass an array of addresses if this message is from multiple people. You may also specify sender name in addition to email address using format: [email => name].
Gmail disallows overriding the FROM name except from verfied email addresses that you prove to gmail you own. Either choose a different email server or go to your gmail settings and change it to another valid email address that you can receive email from.
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