Answer the question
In order to leave comments, you need to log in
How to send emails via swiftMailer in Yii2?
Hello. I can't finally figure out how to use the swiftMailer extension in Yii2 after all . Judging by the fact that I did not find any questions on this topic, the task is trivial, but I could not figure it out to the end.
There are examples that do not describe in more detail the entire cycle of sending a letter, or I don’t understand something
:(
return [
//....
'components' => [
......
'mail' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'localhost',
'username' => 'username',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
],
],
]
];
Yii::$app->mail->compose()
->setTo($toEmail)
->setFrom([$this->email => $this->name])
->setSubject($this->subject)
->setTextBody($this->body)
->send();
Answer the question
In order to leave comments, you need to log in
The answer is of course outdated, but many may be useful. This is how you can get a log of the entire process of sending a message, and there it becomes clear what the problem is.
$mailer = Yii::$app->get('mailer');
$message = $mailer->compose() ... ;
$logger = new Swift_Plugins_Loggers_ArrayLogger();
$mailer->getSwiftMailer()->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
if (!$message->send()) {
echo $logger->dump();
}
'host' => 'smtp.mail.ru',
'username' => '[email protected]',
'password' => 'password of [email protected]',
'port' => '587',
obviously
www.yiiframework.com/wiki/656/how-to-send-emails-u...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question