|
- <?php
-
- namespace backend\models;
-
- use Yii;
- use yii\base\Model;
-
- /**
- * ContactForm is the model behind the contact form.
- */
- class MailForm extends Model {
-
- public $subject;
- public $body;
-
- /**
- * @inheritdoc
- */
- public function rules() {
- return [
- // name, email, subject and body are required
- [['subject', 'body'], 'required', 'message' => 'Champs obligatoire'],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels() {
- return [
- 'subject' => 'Sujet',
- 'body' => 'Message',
- ];
- }
-
- /**
- * Sends an email to the specified email address using the information collected by this model.
- *
- * @param string $email the target email address
- * @return boolean whether the email was sent
- */
- public function sendEmail($email) {
-
- return Yii::$app->mailer->compose()
- ->setTo($email)
- ->setFrom(['matthieu@lechatdesnoisettes.com' => 'Le Chat des Noisettes'])
- ->setSubject($this->subject)
- ->setTextBody($this->body)
- ->send();
- }
-
- }
|