I am using yii2 default contact us page to get mail from user.. It is working fine but I am getting mail from email which I mention in code, to adminEmail
which is also my email id.
here is code=>
public function sendEmail($email)
{
return Yii::$app->mailer->compose()
->setTo($email)
->setFrom([$this->email => $this->name])//want the data from email field..how to achieve that??
->setSubject($this->subject)
->setTextBody($this->body)
->send();
}
if I try like this ->setFrom([$this->email => $this->email])
in above code I get 2 email id in recieved email
1st $this->email
is username
which is mention in mailer of below code
2nd $this->email
is email id which is filled in contact us form which I want.
in file- common\config\main-local.php
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'pharmadarshu@gmail.com',
'password' => '*****',
'port' => '587',
'encryption' => 'tls',
],
but then I am unable to get name ? I want to receive all fields of contact us form i.e. name, email, subject, body ? I fact all are getting properly except email? can anyone help??
hope described properly my question..