Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

ContactForm.php 1.7KB

8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace common\models;
  3. use Yii;
  4. use yii\base\Model;
  5. /**
  6. * ContactForm is the model behind the contact form.
  7. */
  8. class ContactForm extends Model {
  9. public $name;
  10. public $email;
  11. public $subject;
  12. public $body;
  13. public $verifyCode;
  14. /**
  15. * @inheritdoc
  16. */
  17. public function rules() {
  18. return [
  19. // name, email, subject and body are required
  20. [['name', 'email', 'subject', 'body'], 'required', 'message' => 'Champs obligatoire'],
  21. // email has to be a valid email address
  22. ['email', 'email', 'message' => 'Email incorrect'],
  23. // verifyCode needs to be entered correctly
  24. ['verifyCode', 'captcha', 'message' => 'Veuillez recopier le code de vérification'],
  25. ];
  26. }
  27. /**
  28. * @inheritdoc
  29. */
  30. public function attributeLabels() {
  31. return [
  32. 'name' => 'Nom',
  33. 'email' => 'Email',
  34. 'subject' => 'Sujet',
  35. 'body' => 'Message',
  36. 'verifyCode' => 'Code de vérification',
  37. ];
  38. }
  39. /**
  40. * Sends an email to the specified email address using the information collected by this model.
  41. *
  42. * @param string $email the target email address
  43. * @return boolean whether the email was sent
  44. */
  45. public function sendEmail($email) {
  46. return Yii::$app->mailer->compose([
  47. 'html' => 'contact-html',
  48. 'text' => 'contact-text'], [ 'content' => $this->body,
  49. 'nom' => $this->name
  50. ])
  51. ->setTo($email)
  52. ->setFrom([$this->email => $this->name])
  53. ->setSubject('[La boîte à pain] Contact : ' . $this->subject)
  54. ->send();
  55. }
  56. }