frontend\models\ContactForm::sendEmail PHP Method

sendEmail() public method

Sends an email to the specified email address using the information collected by this model.
public sendEmail ( string $email ) : boolean
$email string the target email address
return boolean whether the email was sent
    public function sendEmail($email)
    {
        return Yii::$app->mailer->compose()->setTo($email)->setFrom([$this->email => $this->name])->setSubject($this->subject)->setTextBody($this->body)->send();
    }

Usage Example

Exemplo n.º 1
0
 public function actionFeedback()
 {
     $model = new ContactForm();
     if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail(Yii::$app->settings->get('main.supportEmail'))) {
             return 'Спасибо за ваше сообщение, мы обязательно ответим вам в ближайшее время.';
         } else {
             return 'Что то пошло не так :( Попробуйте позднее';
         }
     }
     return 'Что то пошло не так :(';
 }
All Usage Examples Of frontend\models\ContactForm::sendEmail