You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MailForm.php 1.1KB

8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace backend\models;
  3. use Yii;
  4. use yii\base\Model;
  5. /**
  6. * ContactForm is the model behind the contact form.
  7. */
  8. class MailForm extends Model {
  9. public $subject;
  10. public $body;
  11. /**
  12. * @inheritdoc
  13. */
  14. public function rules() {
  15. return [
  16. // name, email, subject and body are required
  17. [['subject', 'body'], 'required', 'message' => 'Champs obligatoire'],
  18. ];
  19. }
  20. /**
  21. * @inheritdoc
  22. */
  23. public function attributeLabels() {
  24. return [
  25. 'subject' => 'Sujet',
  26. 'body' => 'Message',
  27. ];
  28. }
  29. /**
  30. * Sends an email to the specified email address using the information collected by this model.
  31. *
  32. * @param string $email the target email address
  33. * @return boolean whether the email was sent
  34. */
  35. public function sendEmail($email) {
  36. return Yii::$app->mailer->compose()
  37. ->setTo($email)
  38. ->setFrom(['matthieu@lechatdesnoisettes.com' => 'Le Chat des Noisettes'])
  39. ->setSubject($this->subject)
  40. ->setTextBody($this->body)
  41. ->send();
  42. }
  43. }