Я пытаюсь отправить электронное письмо, используя компонент почтовой программы yii2.
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',
]
],
И мой код.
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()
Я получаю эту ошибку.
Swift_TransportException Ожидаемый код ответа 250, но получил код
«535», с сообщением «535-5.7.8 Имя пользователя и пароль не принимаются.
Узнайте больше на 535 5.7.8
https://support.google.com/mail/?p=BadCredentials
a13-v6sm4133042wrc.19 - gsmtp "
Я уже настроил свою учетную запись Gmail, как сказано здесь введите описание ссылки здесь
менее безопасное приложение на вашей учетной записи Gmail
И я также пытаюсь использовать ssl вместо 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',
]
],
Есть идеи? Спасибо!