updated apps to use the mail component.
This commit is contained in:
parent
4df6370173
commit
e1561bc3d1
@ -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"
|
||||||
|
@ -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' => [
|
||||||
|
@ -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…
Reference in New Issue
Block a user