Answer the question
In order to leave comments, you need to log in
How to set default sender mail for yii\swiftmailer\Mailer?
I send mail via yandex. In yii2 config:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.yandex.ru',
'username' => '[email protected]',
'password' => 'mypassword',
'port' => '465',
'encryption' => 'SSL',
],
],
Yii::$app->mailer->compose()
->setFrom('[email protected]')
->setTo('...')
->setSubject('...')
->setHtmlBody('...')
->send();
Yii::$app->mailer->compose()
->setTo('...')
->setSubject('...')
->setHtmlBody('...')
->send();
Swift_TransportException
Cannot send message without a sender address
Answer the question
In order to leave comments, you need to log in
any message settings can be set through the messageConfig property , for example:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.yandex.ru',
'username' => '[email protected]',
'password' => 'mypassword',
'port' => '465',
'encryption' => 'SSL',
],
'messageConfig' => [
'from' => ['[email protected]' => 'Site Name'],
],
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question