Yii2:无法从表单发送电子邮件

时间:2015-07-15 12:46:19

标签: php mysql email yii2

<div class="status-form">

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model,'job_code')->widget(Select2::classname(),[
            'data'=>ArrayHelper::map(CreateJob::find()->all(),'job_id','job_code'),
            'language'=>'en',
            'options'=>['placeholder' => 'Select Job Code','id'=>'empCode'],
            'pluginOptions' =>[

            ],
        ]); ?>

    <?= $form->field($model, 'job_code')->hiddenInput()->label(false); ?>

    <?= $form->field($model, 'client_code')->textInput(['readonly' => true]) ?>

    <?= $form->field($model, 'company_name')->textInput(['readonly' => true]) ?>

    <?= $form->field($model, 'emp_email')->hiddenInput()->label(false); ?>

    <?= $form->field($model, 'emp_mobile')->hiddenInput()->label(false); ?>

    <?= $form->field($model, 'emp_first_name')->hiddenInput()->label(false); ?>

    <?= $form->field($model, 'emp_last_name')->hiddenInput()->label(false); ?>

    <?= $form->field($model, 'job_description')->textarea(['rows' => 6]) ?>

    <?= $form->field($model, 'status')->radioList(array('Approved'=>'Approved','Digital'=>'Digital','CDP'=>'CDP','Print'=>'Print','Other Process'=>'Other Process','Packing'=>'Packing','Dispatch'=>'Dispatch'),['class' => $model->status ? 'btn-group' : 'btn btn-default'],array('onChange'=>'toggleSSN();'),['id'=>'radioButtons'] );                   ?>


    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>

控制器

public function actionCreate()
    {
        $model = new Status();
       $email = new Emails();

        if ($model->load(Yii::$app->request->post())) 
        {

                $value=Yii::$app->mailer->compose()
                ->setFrom(["xyz@gmail.com"])
                ->setTo($model->emp_email)
                ->setsubject('Job Status')
                ->setHtmlBody($model->job_description)
                ->send();

            $model->save();
            $email->save();

            return $this->redirect(['view', 'id' => $model->id]);
        } 
        else 
        {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }

我想向客户发送有关其当前工作状态的电子邮件。当用户粘贴提交时,它应该从填写的表单字段向客户端发送电子邮件。 此外,我需要为此电子邮件设置模板,以便只有客户信息不会改变其他部分。

1 个答案:

答案 0 :(得分:0)

首先从提交按钮中删除div class =“active form”,然后按钮将起作用。

<div class="form-group">
    <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>

<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>