Class frontend\models\ContactForm

Inheritancefrontend\models\ContactForm » yii\base\Model
Source Code https://github.com/yiisoft/yii2-app-advanced/blob/master/frontend/models/ContactForm.php

ContactForm is the model behind the contact form.

Public Methods

Hide inherited methods

Method Description Defined By
attributeLabels() frontend\models\ContactForm
rules() frontend\models\ContactForm
sendEmail() Sends an email to the specified email address using the information collected by this model. frontend\models\ContactForm

Property Details

Hide inherited properties

$body public property
public $body null
$email public property
public $email null
$name public property
public $name null
$subject public property
public $subject null
$verifyCode public property
public $verifyCode null

Method Details

Hide inherited methods

attributeLabels() public method

public void attributeLabels ( )

                public function attributeLabels()
{
    return [
        'verifyCode' => 'Verification Code',
    ];
}

            
rules() public method

public void rules ( )

                public function rules()
{
    return [
        // name, email, subject and body are required
        [['name', 'email', 'subject', 'body'], 'required'],
        // email has to be a valid email address
        ['email', 'email'],
        // verifyCode needs to be entered correctly
        ['verifyCode', 'captcha'],
    ];
}

            
sendEmail() public method

Sends an email to the specified email address using the information collected by this model.

public boolean sendEmail ( $email )
$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([Yii::$app->params['senderEmail'] => Yii::$app->params['senderName']])
        ->setReplyTo([$this->email => $this->name])
        ->setSubject($this->subject)
        ->setTextBody($this->body)
        ->send();
}