Class app\models\ContactForm
Inheritance | app\models\ContactForm » yii\base\Model |
---|---|
Source Code | https://github.com/yiisoft/yii2-app-basic/blob/master/models/ContactForm.php |
ContactForm is the model behind the contact form.
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$body | app\models\ContactForm | ||
app\models\ContactForm | |||
$name | app\models\ContactForm | ||
$subject | app\models\ContactForm | ||
$verifyCode | app\models\ContactForm |
Public Methods
Method | Description | Defined By |
---|---|---|
attributeLabels() | app\models\ContactForm | |
contact() | Sends an email to the specified email address using the information collected by this model. | app\models\ContactForm |
rules() | app\models\ContactForm |
Property Details
Method Details
public array attributeLabels ( ) | ||
return | array |
Customized attribute labels |
---|
public function attributeLabels()
{
return [
'verifyCode' => 'Verification Code',
];
}
Sends an email to the specified email address using the information collected by this model.
public boolean contact ( $email ) | ||
string |
The target email address |
|
return | boolean |
Whether the model passes validation |
---|
public function contact($email)
{
if ($this->validate()) {
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();
return true;
}
return false;
}
public array rules ( ) | ||
return | array |
The validation 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'],
];
}