Dominus77 / yii2-advanced-start

Yii2 Start Project Advanced Template

Home Page:https://dominus77.github.io/yii2-advanced-start/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sender's mail is wrong in the ContactForm

polinwei opened this issue · comments

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

    public function actionContact()
    {
        $model = new ContactForm();
        if(Yii::$app->user->isGuest)
            $model->scenario = $model::SCENARIO_GUEST;

        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
            if ($model->sendEmail(Yii::$app->params['adminEmail'])) {
                Yii::$app->session->setFlash('success', Yii::t('app', 'Thank you for contacting us. We will respond to you as soon as possible.'));
            } else {
                Yii::$app->session->setFlash('error', Yii::t('app', 'There was an error sending email.'));
            }

            return $this->refresh();
        } else {
            return $this->render('contact', [
                'model' => $model,
            ]);
        }
    }

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.