Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- public function actionContact()
- {
- $model = new ContactForm();
- if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
- Yii::$app->session->setFlash('contactFormSubmitted');
- return $this->refresh();
- } else {
- return $this->render('contact', [
- 'model' => $model]);
- }
- }
- ?>
- <?php
- public function contact($email)
- {
- $content = "<p>Email: " . $this->email . "</p>";
- $content .= "<p>Name: " . $this->name . "</p>";
- $content .= "<p>Subject: " . $this->subject . "</p>";
- $content .= "<p>Body: " . $this->body . "</p>";
- if ($this->validate()) {
- Yii::$app->mailer->compose("@app/mail/layouts/html", ["content" => $content])
- ->setTo($email)
- ->setFrom([$this->email => $this->name])
- ->setSubject($this->subject)
- ->setTextBody($this->body)
- ->send();
- return true;
- } else {
- return false;
- }
- }
- <?php
- 'mailer' => [
- 'class' => 'yiiswiftmailerMailer',
- 'useFileTransport' => false,
- // send all mails to a file by default. You have to set
- // 'useFileTransport' to false and configure a transport
- // for the mailer to send real emails.
- 'transport' => [
- 'class' => 'Swift_SmtpTransport',
- 'host' => 'smtp.gmail.com',
- 'username' => 'mymail@gmail.com',
- 'password' => 'password',
- 'port' => '587',
- 'encryption' => 'tls',],
- ],
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement