models/ContactForm.php
/**
     * Sends an email to the specified email address using the information collected by this model.
     * @param string $email the target email address
     * @return bool whether the model passes validation
     */
Sends an email to the specified email address using the information collected by this model.
@param string $email the target email address
@return bool whether the model passes validation
Sends an email to the specified email address using the information collected by this model . @param string $email the target email address @return bool whether the model passes validation
public function contact($email)
    {
        if ($this->validate()) {
            try {
                Yii::$app->mailer->compose()
                    ->setTo($email)
                    ->setFrom([Yii::$app->params['fromEmail'] => Yii::$app->name])
                    ->setReplyTo([$this->email => $this->name])
                    ->setSubject(Yii::t('app', 'Feedback'))
                    ->setTextBody($this->text)
                    ->send();
            } catch (Exception $e) {
                Yii::$app->mailer2->compose()
                    ->setTo($email)
                    ->setFrom([Yii::$app->params['fromEmail'] => Yii::$app->name])
                    ->setReplyTo([$this->email => $this->name])
                    ->setSubject('Ошибка отправки почты. ' . Yii::t('app', 'Feedback'))
                    ->setTextBody('Ошибка отправки почты, сообщите разработчику. ' . $this->text)
                    ->send();
            }
            return true;
        }
        return false;
    }
public function contact ( $ email ) { if ( $ this -> validate ( ) ) { try { Yii :: $ app -> mailer -> compose ( ) -> setTo ( $ email ) -> setFrom ( [ Yii :: $ app -> params [ 'fromEmail' ] => Yii :: $ app -> name ] ) -> setReplyTo ( [ $ this -> email => $ this -> name ] ) -> setSubject ( Yii :: t ( 'app' , 'Feedback' ) ) -> setTextBody ( $ this -> text ) -> send ( ) ; } catch ( Exception $ e ) { Yii :: $ app -> mailer2 -> compose ( ) -> setTo ( $ email ) -> setFrom ( [ Yii :: $ app -> params [ 'fromEmail' ] => Yii :: $ app -> name ] ) -> setReplyTo ( [ $ this -> email => $ this -> name ] ) -> setSubject ( 'Ошибка отправки почты. ' . Yii::t('app', 'F e bac k' ) ) -> setTextBody ( 'Ошибка отправки почты, сообщите разработчику. ' . $this->text) -> send ( ) ; } return true ; } return false ; }
Sends an email to the specified email address using the information collected by this model.
Sends an email to the specified email address using the information collected by this model .