updated apps to use the mail component.

This commit is contained in:
Qiang Xue 2013-11-07 23:01:13 -05:00
parent 4df6370173
commit e1561bc3d1
3 changed files with 11 additions and 7 deletions

View File

@ -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"

View File

@ -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' => [

View File

@ -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;