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

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -