Class frontend\models\ContactForm
| Inheritance | frontend\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 Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $body | frontend\models\ContactForm | ||
| frontend\models\ContactForm | |||
| $name | frontend\models\ContactForm | ||
| $subject | frontend\models\ContactForm | ||
| $verifyCode | frontend\models\ContactForm |
Public 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
Method Details
| public attributeLabels ( ) |
public function attributeLabels()
{
return [
'verifyCode' => 'Verification Code',
];
}
| public 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'],
];
}
Sends an email to the specified email address using the information collected by this model.
| public boolean sendEmail ( string $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();
}