No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

53 líneas
1.1KB

  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. }