Browse Source

updated apps to use the mail component.

tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
998cf7e675
  1. 1
      apps/advanced/backend/config/main.php
  2. 4
      apps/advanced/common/config/params.php
  3. 1
      apps/advanced/composer.json
  4. 1
      apps/advanced/console/config/main.php
  5. 1
      apps/advanced/frontend/config/main.php
  6. 1
      apps/advanced/frontend/controllers/SiteController.php
  7. 14
      apps/advanced/frontend/models/ContactForm.php
  8. 1
      apps/basic/composer.json
  9. 3
      apps/basic/config/web.php
  10. 14
      apps/basic/models/ContactForm.php

1
apps/advanced/backend/config/main.php

@ -22,6 +22,7 @@ return [
], ],
'db' => $params['components.db'], 'db' => $params['components.db'],
'cache' => $params['components.cache'], 'cache' => $params['components.cache'],
'mail' => $params['components.mail'],
'user' => [ 'user' => [
'identityClass' => 'common\models\User', 'identityClass' => 'common\models\User',
], ],

4
apps/advanced/common/config/params.php

@ -12,6 +12,10 @@ return [
'class' => 'yii\caching\FileCache', 'class' => 'yii\caching\FileCache',
], ],
'components.mail' => [
'class' => 'yii\swiftmailer\Mailer',
],
'components.db' => [ 'components.db' => [
'class' => 'yii\db\Connection', 'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yii2advanced', 'dsn' => 'mysql:host=localhost;dbname=yii2advanced',

1
apps/advanced/composer.json

@ -16,6 +16,7 @@
"require": { "require": {
"php": ">=5.4.0", "php": ">=5.4.0",
"yiisoft/yii2": "dev-master", "yiisoft/yii2": "dev-master",
"yiisoft/yii2-swiftmailer": "dev-master",
"yiisoft/yii2-bootstrap": "dev-master", "yiisoft/yii2-bootstrap": "dev-master",
"yiisoft/yii2-debug": "dev-master", "yiisoft/yii2-debug": "dev-master",
"yiisoft/yii2-gii": "dev-master" "yiisoft/yii2-gii": "dev-master"

1
apps/advanced/console/config/main.php

@ -19,6 +19,7 @@ return [
'components' => [ 'components' => [
'db' => $params['components.db'], 'db' => $params['components.db'],
'cache' => $params['components.cache'], 'cache' => $params['components.cache'],
'mail' => $params['components.mail'],
'log' => [ 'log' => [
'targets' => [ 'targets' => [
[ [

1
apps/advanced/frontend/config/main.php

@ -23,6 +23,7 @@ return [
], ],
'db' => $params['components.db'], 'db' => $params['components.db'],
'cache' => $params['components.cache'], 'cache' => $params['components.cache'],
'mail' => $params['components.mail'],
'user' => [ 'user' => [
'identityClass' => 'common\models\User', 'identityClass' => 'common\models\User',
], ],

1
apps/advanced/frontend/controllers/SiteController.php

@ -159,6 +159,7 @@ class SiteController extends Controller
$user->password_reset_token = Security::generateRandomKey(); $user->password_reset_token = Security::generateRandomKey();
if ($user->save(false)) { if ($user->save(false)) {
// todo: refactor it with mail component. pay attention to the arrangement of mail view files
$fromEmail = \Yii::$app->params['supportEmail']; $fromEmail = \Yii::$app->params['supportEmail'];
$name = '=?UTF-8?B?' . base64_encode(\Yii::$app->name . ' robot') . '?='; $name = '=?UTF-8?B?' . base64_encode(\Yii::$app->name . ' robot') . '?=';
$subject = '=?UTF-8?B?' . base64_encode('Password reset for ' . \Yii::$app->name) . '?='; $subject = '=?UTF-8?B?' . base64_encode('Password reset for ' . \Yii::$app->name) . '?=';

14
apps/advanced/frontend/models/ContactForm.php

@ -2,6 +2,7 @@
namespace frontend\models; namespace frontend\models;
use Yii;
use yii\base\Model; use yii\base\Model;
/** /**
@ -48,13 +49,12 @@ class ContactForm extends Model
public function contact($email) public function contact($email)
{ {
if ($this->validate()) { if ($this->validate()) {
$name = '=?UTF-8?B?' . base64_encode($this->name) . '?='; Yii::$app->mail->compose()
$subject = '=?UTF-8?B?' . base64_encode($this->subject) . '?='; ->setTo($email)
$headers = "From: $name <{$this->email}>\r\n" . ->setFrom([$this->email => $this->name])
"Reply-To: {$this->email}\r\n" . ->setSubject($this->subject)
"MIME-Version: 1.0\r\n" . ->setTextBody($this->body)
"Content-type: text/plain; charset=UTF-8"; ->send();
mail($email, $subject, $this->body, $headers);
return true; return true;
} else { } else {
return false; return false;

1
apps/basic/composer.json

@ -16,6 +16,7 @@
"require": { "require": {
"php": ">=5.4.0", "php": ">=5.4.0",
"yiisoft/yii2": "dev-master", "yiisoft/yii2": "dev-master",
"yiisoft/yii2-swiftmailer": "dev-master",
"yiisoft/yii2-bootstrap": "dev-master", "yiisoft/yii2-bootstrap": "dev-master",
"yiisoft/yii2-debug": "dev-master", "yiisoft/yii2-debug": "dev-master",
"yiisoft/yii2-gii": "dev-master" "yiisoft/yii2-gii": "dev-master"

3
apps/basic/config/web.php

@ -17,6 +17,9 @@ $config = [
'errorHandler' => [ 'errorHandler' => [
'errorAction' => 'site/error', 'errorAction' => 'site/error',
], ],
'mail' => [
'class' => 'yii\swiftmailer\Mailer',
],
'log' => [ 'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0, 'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [ 'targets' => [

14
apps/basic/models/ContactForm.php

@ -2,6 +2,7 @@
namespace app\models; namespace app\models;
use Yii;
use yii\base\Model; use yii\base\Model;
/** /**
@ -48,13 +49,12 @@ class ContactForm extends Model
public function contact($email) public function contact($email)
{ {
if ($this->validate()) { if ($this->validate()) {
$name = '=?UTF-8?B?' . base64_encode($this->name) . '?='; Yii::$app->mail->compose()
$subject = '=?UTF-8?B?' . base64_encode($this->subject) . '?='; ->setTo($email)
$headers = "From: $name <{$this->email}>\r\n" . ->setFrom([$this->email => $this->name])
"Reply-To: {$this->email}\r\n" . ->setSubject($this->subject)
"MIME-Version: 1.0\r\n" . ->setTextBody($this->body)
"Content-type: text/plain; charset=UTF-8"; ->send();
mail($email, $subject, $this->body, $headers);
return true; return true;
} else { } else {
return false; return false;

Loading…
Cancel
Save