Cakephp 3 未知电子邮件错误
Cakephp 3 Unknown Email error
我想问一下在cakephp3中发送邮件的问题。
我正在使用 cakephp3 文档,并按照示例所示配置了所有内容。
但是,当我尝试发送邮件时,出现了这个错误:
Could not send email: unknown
//app.php
'EmailTransport' => [
'default' => [
'className' => 'Mail',
// The following keys are used in SMTP transports
'host' => 'smtp.gmail.om',
'port' => 465,
'timeout' => 30,
'username' => 'mymail@gmail.com',
'password' => 'password',
'client' => null,
'tls' => null,
],
],
联系人控制器:
public function contact() {
if (isset($this->request->data) AND ($this->request->is('post'))) {
$email = new Email('default');
if ($email->from(['mymail@gmail.com' => 'My Site'])->to('othermail@gmail.com')->subject('Hello')->send('Message')) {
//pr( 'ok');
}
}
}
这是一般性错误消息吗(在我看来,这可能有很多原因)?它在调试上下文中没有价值。
默认配置中的主机名不正确。
应该是
'host' => 'smtp.gmail.com',
而不是
'host' => 'smtp.gmail.om',
您想使用 SMTP 服务器,但您已配置为使用 Mail
传输!
className
选项应设置为 Smtp
。主机可能也应该不同(ssl://
前缀),或者您应该启用 TLS,请确保您通读了通过下面的搜索链接找到的 questions/answers。
另见
use Cake\Mailer\Email;
Email::configTransport('gmail', [
'host' => 'smtp.gmail.com',
'port' => 587,
'username' => 'my@gmail.com',
'password' => 'secret',
'className' => 'Smtp',
'tls' => true
]);
您使用此代码:将 My@gmail.com 和 Secret 替换为您的凭据,然后使用您的代码即可。
总是被遗忘的一件事是电子邮件配置文件
`'Email' => [
'default' => [
'transport' => 'gmail', //this allows the email class to use the gmail settings
'from' => 'youremail@gmail.com',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
],
],`
顺便说一下,您可以为测试、开发等设置多个配置文件
我想问一下在cakephp3中发送邮件的问题。
我正在使用 cakephp3 文档,并按照示例所示配置了所有内容。
但是,当我尝试发送邮件时,出现了这个错误:
Could not send email: unknown
//app.php
'EmailTransport' => [
'default' => [
'className' => 'Mail',
// The following keys are used in SMTP transports
'host' => 'smtp.gmail.om',
'port' => 465,
'timeout' => 30,
'username' => 'mymail@gmail.com',
'password' => 'password',
'client' => null,
'tls' => null,
],
],
联系人控制器:
public function contact() {
if (isset($this->request->data) AND ($this->request->is('post'))) {
$email = new Email('default');
if ($email->from(['mymail@gmail.com' => 'My Site'])->to('othermail@gmail.com')->subject('Hello')->send('Message')) {
//pr( 'ok');
}
}
}
这是一般性错误消息吗(在我看来,这可能有很多原因)?它在调试上下文中没有价值。
默认配置中的主机名不正确。
应该是
'host' => 'smtp.gmail.com',
而不是
'host' => 'smtp.gmail.om',
您想使用 SMTP 服务器,但您已配置为使用 Mail
传输!
className
选项应设置为 Smtp
。主机可能也应该不同(ssl://
前缀),或者您应该启用 TLS,请确保您通读了通过下面的搜索链接找到的 questions/answers。
另见
use Cake\Mailer\Email;
Email::configTransport('gmail', [
'host' => 'smtp.gmail.com',
'port' => 587,
'username' => 'my@gmail.com',
'password' => 'secret',
'className' => 'Smtp',
'tls' => true
]);
您使用此代码:将 My@gmail.com 和 Secret 替换为您的凭据,然后使用您的代码即可。
总是被遗忘的一件事是电子邮件配置文件
`'Email' => [
'default' => [
'transport' => 'gmail', //this allows the email class to use the gmail settings
'from' => 'youremail@gmail.com',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
],
],`
顺便说一下,您可以为测试、开发等设置多个配置文件