Yii2 SwiftMailer sending email via remote smtp server (gmail) -
Yii2 SwiftMailer sending email via remote smtp server (gmail) -
i want send emails via gmail account.
my mailer config:
[ 'class' => 'yii\swiftmailer\mailer', 'usefiletransport' => false,//set property false send mails real email addresses 'transport' => [ 'class' => 'swift_smtptransport', 'host' => 'smtp.gmail.com', 'username' => 'my@gmail.com', 'password' => 'pass', 'port' => '587', 'encryption' => 'tls', ], ]
i wrote command mailcontroller:
<?php namespace app\commands; utilize yii\console\controller; utilize yii; /** * sanding mail service * class mailcontroller * @package app\commands */ class mailcontroller extends controller { private $from = 'my@gmail.com'; private $to = 'to@gmail.com'; public function actionindex($type = 'test', $data = null) { yii::$app->mailer->compose($type, ['data' => $data]) ->setfrom($this->from) ->setto($this->to) ->setsubject($this->subjects[$type]) ->send(); } }
when i'm trying run: php yii mail
i get: sh: 1: /usr/sbin/sendmail: not found
but why requires sendmail if want smtp connection smtp.gmail.com?
i think have configured mailer wrongly. because still using default mail service function. documentation configuration should below. mailer should within components
.
'components' => [ ... 'mailer' => [ 'class' => 'yii\swiftmailer\mailer', 'transport' => [ 'class' => 'swift_smtptransport', 'host' => 'smtp.gmail.com', 'username' => 'username', 'password' => 'password', 'port' => '587', 'encryption' => 'tls', ], ], ... ],
one more suggestion utilize port "465" , encryption "ssl" instead of port "587", encryption "tls".
yii2 swiftmailer
Comments
Post a Comment