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": {
"php": ">=5.4.0",
"yiisoft/yii2": "dev-master",
"yiisoft/yii2-swiftmailer": "dev-master",
"yiisoft/yii2-bootstrap": "dev-master",
"yiisoft/yii2-debug": "dev-master",
"yiisoft/yii2-gii": "dev-master"

View File

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

View File

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