如何配置 CakePHP 3.x 以使用 Amazon SES SMTP 发送电子邮件?
How to configure CakePHP 3.x to use Amazon SES SMTP to send out emails?
我已经在 AWS SES 中成功创建了我的 SMTP 凭证。
我解除了限制。
我已经使用 command line 来测试我的凭据是否正常。
他们是。
我正在使用 CakePHP 3.2,但仍然无法发送电子邮件。
我使用的地区是美国西俄勒冈州。主持人是email-smtp.us-west-2.amazonaws.com
如何通过命令行测试凭据是否正常
- 打开你的服务器终端并输入
echo -n "YOUR SMTP USERNAME" | base64
- 将输出复制粘贴到某处。你会需要它。输出应以
=
结尾
- 对
YOUR SMTP PASSWORD
重复第 1 步和第 2 步
- 将以下内容复制粘贴到文本文件中,但将
<whatever>
替换为您认为合适的内容。
像这样:
AFTER 220 .... PASTE THE LINE BELOW:
EHLO <example.com>
AFTER 250 Ok PASTE THE LINE BELOW:
AUTH LOGIN
AFTER 334 VXNlcm5hbWU6:
<YOUR SMTP USERNAME encoded as base64 from step 1>
AFTER 334 UGFzc3dvcmQ6:
<YOUR SMTP PASSWORD encoded as base64 from step 3>
AFTER 235 Authentication successful.
MAIL FROM:<yourverifiedemail@example.com>
AFTER 250 Ok
RCPT TO:<yourverifiedemail@example.com>
AFTER 250 Ok
DATA
AFTER 354 End data with <CR><LF>.<CR><LF>
Subject:Hello from Amazon SES!
This email was sent using the Amazon SES SMTP interface.
.
在您的终端中输入 openssl s_client -crlf -quiet -connect email-smtp.us-west-2.amazonaws.com:465
按照文本文件中的说明进行操作。
一旦确定凭证是正确的,现在配置你的 cakephp 3.x
配置蛋糕3.x
打开你的config/app.php
找到 EmailTransport
并添加低于默认值的新传输
像这样:
'EmailTransport' => [
'default' => [
'className' => 'Mail',
// The following keys are used in SMTP transports
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null,
'tls' => null,
],
// START of what you need to add!!
'AWS_SES' =>[
'className' => 'Smtp',
'host' => 'email-smtp.us-west-2.amazonaws.com',
'port' => 587, // this is very important to be 587!!
'timeout' => 30,
'username' => 'YOUR SMTP USERNAME',
'password' => 'YOUR SMTP PASSWORD',
'tls' => true, // this is also very important!!
]
// END of what you need to add!!
],
- 现在在
app.php
中查找 Email
并在默认设置下添加新配置文件
像这样:
'Email' => [
'default' => [
'transport' => 'default',
'from' => 'you@localhost',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
],
// START of what you need to add!
'production' => [
'transport' => 'AWS_SES',
//'log' => true,
]
// END of what you need to add!
],
- 配置到此结束!
- 只需在您想要的适当位置调用
$email = new Email('production');
。
我已经在 AWS SES 中成功创建了我的 SMTP 凭证。
我解除了限制。
我已经使用 command line 来测试我的凭据是否正常。
他们是。
我正在使用 CakePHP 3.2,但仍然无法发送电子邮件。
我使用的地区是美国西俄勒冈州。主持人是email-smtp.us-west-2.amazonaws.com
如何通过命令行测试凭据是否正常
- 打开你的服务器终端并输入
echo -n "YOUR SMTP USERNAME" | base64
- 将输出复制粘贴到某处。你会需要它。输出应以
=
结尾
- 对
YOUR SMTP PASSWORD
重复第 1 步和第 2 步
- 将以下内容复制粘贴到文本文件中,但将
<whatever>
替换为您认为合适的内容。
像这样:
AFTER 220 .... PASTE THE LINE BELOW:
EHLO <example.com>
AFTER 250 Ok PASTE THE LINE BELOW:
AUTH LOGIN
AFTER 334 VXNlcm5hbWU6:
<YOUR SMTP USERNAME encoded as base64 from step 1>
AFTER 334 UGFzc3dvcmQ6:
<YOUR SMTP PASSWORD encoded as base64 from step 3>
AFTER 235 Authentication successful.
MAIL FROM:<yourverifiedemail@example.com>
AFTER 250 Ok
RCPT TO:<yourverifiedemail@example.com>
AFTER 250 Ok
DATA
AFTER 354 End data with <CR><LF>.<CR><LF>
Subject:Hello from Amazon SES!
This email was sent using the Amazon SES SMTP interface.
.
在您的终端中输入
openssl s_client -crlf -quiet -connect email-smtp.us-west-2.amazonaws.com:465
按照文本文件中的说明进行操作。
一旦确定凭证是正确的,现在配置你的 cakephp 3.x
配置蛋糕3.x
打开你的
config/app.php
找到
EmailTransport
并添加低于默认值的新传输
像这样:
'EmailTransport' => [
'default' => [
'className' => 'Mail',
// The following keys are used in SMTP transports
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null,
'tls' => null,
],
// START of what you need to add!!
'AWS_SES' =>[
'className' => 'Smtp',
'host' => 'email-smtp.us-west-2.amazonaws.com',
'port' => 587, // this is very important to be 587!!
'timeout' => 30,
'username' => 'YOUR SMTP USERNAME',
'password' => 'YOUR SMTP PASSWORD',
'tls' => true, // this is also very important!!
]
// END of what you need to add!!
],
- 现在在
app.php
中查找Email
并在默认设置下添加新配置文件
像这样:
'Email' => [
'default' => [
'transport' => 'default',
'from' => 'you@localhost',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
],
// START of what you need to add!
'production' => [
'transport' => 'AWS_SES',
//'log' => true,
]
// END of what you need to add!
],
- 配置到此结束!
- 只需在您想要的适当位置调用
$email = new Email('production');
。