|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Cjt Terabyte LLC [yii2-extension]. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Cjt Terabyte LLC [yii2-extension] <http://github.com/cjtterabytesoft>. |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE.md. |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
* |
|
10
|
|
|
* @link http://www.cjtterabyte.com. |
|
11
|
|
|
* @author Wilmer Arámbula <[email protected]>. |
|
12
|
|
|
* @copyright (c) 2015 Cjt Terabyte LLC. |
|
13
|
|
|
* @Extension: [yii2-adminlte-basic]. |
|
14
|
|
|
* @Models App [ContactForm]. |
|
15
|
|
|
* @since 1.0 |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace cjtterabytesoft\adminlte\basic\models; |
|
19
|
|
|
|
|
20
|
|
|
use Yii; |
|
21
|
|
|
use yii\base\Model; |
|
22
|
|
|
|
|
23
|
|
|
class ContactForm extends Model |
|
24
|
|
|
{ |
|
25
|
|
|
public $name; |
|
26
|
|
|
public $email; |
|
27
|
|
|
public $subject; |
|
28
|
|
|
public $body; |
|
29
|
|
|
public $verifyCode; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @return array the validation rules. |
|
33
|
|
|
*/ |
|
34
|
|
|
public function rules() |
|
35
|
|
|
{ |
|
36
|
|
|
return [ |
|
37
|
|
|
// name, email, subject and body are required |
|
38
|
|
|
[['name', 'email', 'subject', 'body'], 'required'], |
|
39
|
|
|
// email has to be a valid email address |
|
40
|
|
|
['email', 'email'], |
|
41
|
|
|
// verifyCode needs to be entered correctly |
|
42
|
|
|
['verifyCode', 'captcha'], |
|
43
|
|
|
]; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @inheritdoc |
|
48
|
|
|
*/ |
|
49
|
|
|
public function attributeLabels() |
|
50
|
|
|
{ |
|
51
|
|
|
return [ |
|
52
|
|
|
'name' => yii::t('adminlte', 'Name'), |
|
53
|
|
|
'email' => yii::t('adminlte', 'Email'), |
|
54
|
|
|
'subject' => yii::t('adminlte', 'Subject'), |
|
55
|
|
|
'body' => yii::t('adminlte', 'Body'), |
|
56
|
|
|
'verifyCode' => yii::t('adminlte', 'Verification Code'), |
|
57
|
|
|
]; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Sends an email to the specified email address using the information collected by this model. |
|
62
|
|
|
* @param string $email the target email address |
|
63
|
|
|
* @return boolean whether the model passes validation |
|
64
|
|
|
*/ |
|
65
|
|
|
public function sendEmail($email) |
|
66
|
|
|
{ |
|
67
|
|
|
return Yii::$app->mailer->compose() |
|
68
|
|
|
->setTo($email) |
|
69
|
|
|
->setFrom([$this->email => $this->name]) |
|
70
|
|
|
->setSubject($this->subject) |
|
71
|
|
|
->setTextBody($this->body) |
|
72
|
|
|
->send(); |
|
73
|
|
|
} |
|
74
|
|
|
} |