Closed polinwei closed 7 years ago
Hi! It's okay.
if ($model->sendEmail(Yii::$app->params['adminEmail'])) {
Sending email to whom to send a message.
There can be any other address, for example, support
I think put the ContactForm's email should be make seance.
Well, what embarrasses you?
When I received the contact mail , I don't know his email address.
In the email program, click reply and you will see an email address
I received mail as below , It should be Msn <xxx.xx@msn.com>
Therefore , I can not reply.
Msn <polin.wei@myweb.com>
Contact
I have business inquiries or other questions, please contact me. Thank you.
Well, now, click to answer. The answer is sent to user email
setFrom([$this->email => $this->name])
How to set contactform's field: Name&E-mail. example: Msn <xxx.xx@msn.com>
public function sendEmail($email) { return Yii::$app->mailer->compose() ->setTo($email) ->setFrom([$this->email => $this->name]) ->setSubject($this->subject) ->setTextBody($this->body) ->send(); }
Opened the letter in Outlook. I pressed the answer button. The user name is specified. I checked his address. The address that the user specified was inserted.
You can customize as you please. This is no longer true of Yii2. :)
http://www.yiiframework.com/doc-2.0/guide-tutorial-mailing.html
ok. thanks
I did the some codes which refer yours. May you add them?
modules\main\models\frontend\ContactForm.php
public function sendEmail($email) { return Yii::$app->mailer->compose(['text' => '@modules/main/mail/emailContactForm'], ['contactFrom' => $this]) ->setTo($email) ->setFrom([$this->email => $this->name]) ->setSubject($this->subject) //->setTextBody($this->body) ->send(); }
modules/main/mail/emailContactForm.php
use modules\main\Module; Module::t('mail', 'FROM {username}', ['username' => $contactFrom->name ."(". $contactFrom->email .")" ]); $contactFrom->body;
modules/main/messages/en-US/mail.php
/** * Created by PhpStorm. * User: Alexey Shevchenko* Date: 18.10.16 * Time: 18:16 */ return [ 'FROM {username}' => 'From: {username}', ];
You can make changes in your version of yii2-advanced-start. https://github.com/polinwei/yii2-advanced-start
I'm finishing the second version. Soon I will make a release. While she's in the master
Cool.
When I received the mail from contactform , the sender's email is adminEmail , I think it should be the field: email in the contactform
modules\main\controllers\frontend\DefaultController