Answer the question
In order to leave comments, you need to log in
Yii2 Swiftmailer - how to set default sender?
I use Yii2 in the project, in which I set up sending emails through Swiftmailer, which is native to it. You can use setFrom() to specify the sender. But every time when sending letters, doing the same thing, specifying the same sender is inconvenient. Is it possible once, through the config, to specify the sender, which will be substituted by default for each sending of letters?
Answer the question
In order to leave comments, you need to log in
Good afternoon.
Set a parameter in params, where specify the admin's email
// в params.php
return [
'adminEmail' => '[email protected]',
]
// в контроллере
if($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])){
Yii::$app->session->setFlash('contactFormSubmitted');
return $this->refresh();
}
The sender can also be specified in the application config \config\web.php
...
'components' => [
...
'mailer' => [
...
'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