Answer the question
In order to leave comments, you need to log in
How to connect swiftmailer (Yii2) and Yandex mail for domain?
In config:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mail',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.yandex.ru',
'username' => '[email protected]',
'password' => 'тут пароль',
'port' => '465',
'encryption' => 'SSL',
],
],
public function sendEmail()
{
$mailbody = '<h3>Отзыв с сайта</h3>
<p><b>Имя:</b> '.$this->name.'</p>
<p><b>e-mail:</b> '.$this->email.'</p>
<p><b>Тема:</b> '.$this->subject.'</p>
<p><b>Текст:</b></p>
<p>'.$this->body.'</p>
<a href="mailTo:'.$this->email.'">Ответить</a>
';
return Yii::$app->mailer->compose()
->setFrom('[email protected]')
->setTo('[email protected]')
->setSubject($this->subject)
->setTextBody($mailbody)
->send();
}
Answer the question
In order to leave comments, you need to log in
'host' => 'ssl://smtp.yandex.com',
and the rest is all right, just 'encryption' => 'SSL',
need to remove
Carried. I'll add it so I don't forget.
I tried to send via mailbox registered on pdd.yandex.ru and got error
It turned out that it was necessary to enter the mailbox through the web interface and fill in the fields.
It works for me like this:
'mailer' => [
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.yandex.ru',
'username' => 'мыло для домена',
'password' => 'пароль',
'port' => '25',
'encryption' => 'tls',
],
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question