I have a problem here. I created a Contact form in my webpage, which includes: name, surname, email and description. When I submit my form, the email sends, but the senders email is my email. F.e:
http://imageshack.com/a/img922/801/eVyutz.png
my.email@gmail.com shows not the email, which user entered in a form, but mine. And after that when I click Reply button and type a message back, I send it to myself. Why?
Here is what I did:
My mailer:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'my.email@gmail.com',
'password' => 'password',
'port' => '465',
'encryption' => 'ssl',
'streamOptions' => [ 'ssl' =>
[ 'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
]
],
],
My actionContact():
public function actionContact()
{
$model = new Contact();
$model->scenario = Contact::SCENARIO_CREATE;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
if ($model->sendEmail(Yii::$app->params['adminEmail'])) {
Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Success'));
}
else {
Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Failed'));
}
return $this->refresh();
} else {
return $this->render('contact', [
'model' => $model,
]);
}
}
And my model function:
public function sendEmail($email)
{
return Yii::$app->mailer->compose()
->setTo($email)
->setFrom([$this->email => $this->name." ".$this->surname])
->setSubject($this->subject)
->setTextBody($this->text)
->send();
}
Please help me to solve this, what is wrong? Thank you for any help!
I guess there will be something wrong with $email variable. Because when I use setFrom to email, it shows just my email.