Dominus77 / yii2-advanced-start

Yii2 Start Project Advanced Template
https://dominus77.github.io/yii2-advanced-start/
MIT License
23 stars 12 forks source link

Sender's mail is wrong in the ContactForm #7

Closed polinwei closed 7 years ago

polinwei commented 7 years ago

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,
            ]);
        }
    }

Dominus77 commented 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

polinwei commented 7 years ago

I think put the ContactForm's email should be make seance.

Dominus77 commented 7 years ago

Well, what embarrasses you?

polinwei commented 7 years ago

When I received the contact mail , I don't know his email address.

Dominus77 commented 7 years ago

In the email program, click reply and you will see an email address

polinwei commented 7 years ago

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.

Dominus77 commented 7 years ago

Well, now, click to answer. The answer is sent to user email

polinwei commented 7 years ago

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();
    }
Dominus77 commented 7 years ago

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

polinwei commented 7 years ago

ok. thanks

polinwei commented 7 years ago

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}',
];
Dominus77 commented 7 years ago

You can make changes in your version of yii2-advanced-start. https://github.com/polinwei/yii2-advanced-start

Dominus77 commented 7 years ago

I'm finishing the second version. Soon I will make a release. While she's in the master

polinwei commented 7 years ago

Cool.