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 string $body ''
$email public property
public string $email ''
$name public property
public string $name ''
$subject public property
public string $subject ''
$verifyCode public property
public string $verifyCode ''

Method Details

Hide inherited methods

attributeLabels() public method

public attributeLabels ( )

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

            
rules() public method

public rules ( )

                public function rules(): array
{
    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 ( \yii\mail\MailerInterface $mailer, string $email, string $senderEmail, string $senderName )
$mailer \yii\mail\MailerInterface

The mailer component.

$email string

The target email address.

$senderEmail string

The sender email address.

$senderName string

The sender name.

return boolean

Whether the email was sent.

                public function sendEmail(MailerInterface $mailer, string $email, string $senderEmail, string $senderName): bool
{
    return $mailer->compose()
        ->setTo($email)
        ->setFrom([$senderEmail => $senderName])
        ->setReplyTo([$this->email => $this->name])
        ->setSubject($this->subject)
        ->setTextBody($this->body)
        ->send();
}