【发布时间】:2015-04-12 18:10:48
【问题描述】:
我想通过我的 gmail 帐户发送电子邮件。
我的邮件配置:
[
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,//set this property to false to send mails to real email addresses
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'my@gmail.com',
'password' => 'pass',
'port' => '587',
'encryption' => 'tls',
],
]
我写了命令MailController:
<?php
namespace app\commands;
use yii\console\Controller;
use Yii;
/**
* Sanding mail
* 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();
}
}
当我尝试运行时:php yii mail
我得到:sh: 1: /usr/sbin/sendmail: not found
但是,如果我只想通过 SMTP 连接到 smtp.gmail.com,为什么它需要 sendmail?
【问题讨论】:
-
您确定此电子邮件组件配置用于密钥“邮件程序”吗?根据这个配置,它甚至不应该尝试发送电子邮件,因为“'useFileTransport' => true”意味着它只将消息保存到文件。
标签: yii2 swiftmailer