updated apps to use the mail component.
This commit is contained in:
parent
4df6370173
commit
e1561bc3d1
@ -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"
|
||||
|
@ -17,6 +17,9 @@ $config = [
|
||||
'errorHandler' => [
|
||||
'errorAction' => 'site/error',
|
||||
],
|
||||
'mail' => [
|
||||
'class' => 'yii\swiftmailer\Mailer',
|
||||
],
|
||||
'log' => [
|
||||
'traceLevel' => YII_DEBUG ? 3 : 0,
|
||||
'targets' => [
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user