From e38c34a9357c56fe8b83d1ef33578c06e556e14f Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Tue, 23 Apr 2019 15:11:10 +0300 Subject: [PATCH] Adjusted email headers in contact form See https://github.com/yiisoft/yii2-app-advanced/issues/426 --- config/params.php | 2 ++ models/ContactForm.php | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/config/params.php b/config/params.php index 6ebf279..981c621 100644 --- a/config/params.php +++ b/config/params.php @@ -2,4 +2,6 @@ return [ 'adminEmail' => 'admin@example.com', + 'senderEmail' => 'noreply@example.com', + 'senderName' => 'Example.com mailer', ]; diff --git a/models/ContactForm.php b/models/ContactForm.php index 0b13cb0..f001d21 100644 --- a/models/ContactForm.php +++ b/models/ContactForm.php @@ -52,7 +52,8 @@ class ContactForm extends Model if ($this->validate()) { Yii::$app->mailer->compose() ->setTo($email) - ->setFrom([$this->email => $this->name]) + ->setFrom([Yii::$app->params['senderEmail'] => Yii::$app->params['senderName']]) + ->setReplyTo([$this->email => $this->name]) ->setSubject($this->subject) ->setTextBody($this->body) ->send();