Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. <?php
  2. public function actionContact()
  3. {
  4. $model = new ContactForm();
  5. if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
  6. Yii::$app->session->setFlash('contactFormSubmitted');
  7.  
  8. return $this->refresh();
  9. } else {
  10. return $this->render('contact', [
  11. 'model' => $model]);
  12. }
  13. }
  14. ?>
  15.  
  16. <?php
  17. public function contact($email)
  18. {
  19. $content = "<p>Email: " . $this->email . "</p>";
  20. $content .= "<p>Name: " . $this->name . "</p>";
  21. $content .= "<p>Subject: " . $this->subject . "</p>";
  22. $content .= "<p>Body: " . $this->body . "</p>";
  23. if ($this->validate()) {
  24. Yii::$app->mailer->compose("@app/mail/layouts/html", ["content" => $content])
  25. ->setTo($email)
  26. ->setFrom([$this->email => $this->name])
  27. ->setSubject($this->subject)
  28. ->setTextBody($this->body)
  29. ->send();
  30.  
  31. return true;
  32. } else {
  33. return false;
  34. }
  35. }
  36.  
  37. <?php
  38. 'mailer' => [
  39. 'class' => 'yiiswiftmailerMailer',
  40. 'useFileTransport' => false,
  41. // send all mails to a file by default. You have to set
  42. // 'useFileTransport' to false and configure a transport
  43. // for the mailer to send real emails.
  44. 'transport' => [
  45. 'class' => 'Swift_SmtpTransport',
  46. 'host' => 'smtp.gmail.com',
  47. 'username' => 'mymail@gmail.com',
  48. 'password' => 'password',
  49. 'port' => '587',
  50. 'encryption' => 'tls',],
  51. ],
  52. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement