发送电子邮件时出现 AWS SES Guzzle 错误
AWS SES Guzzle Error when sending email
我已经使用 PHP SDK 设置了 AWS Ses 服务:
$this->client = SesClient::factory([
'key' => $params['key'],
'secretKey' => $params['secret_key'],
'region' => 'eu-west-1',
'base_url' => 'https://email-smtp.eu-west-1.amazonaws.com',
]);
$this->client->sendEmail($this->params());
public function params() {
array(
'Source' => 'verified@gmail.com',
'Destination' => array(
'ToAddresses' => array('receiver@yahoo.com')
),
'Message' => array(
'Subject' => array(
'Data' => 'SES Testing',
'Charset' => 'UTF-8',
),
// Body is required
'Body' => array(
'Text' => array(
'Data' => 'My plain text email',
'Charset' => 'UTF-8',
),
'Html' => array(
'Data' => '<b>My HTML Email</b>',
'Charset' => 'UTF-8',
),
),
),
'ReplyToAddresses' => array( 'replyTo@email.com' ),
'ReturnPath' => 'bounce@email.com'
);
}
尝试发送电子邮件后,我收到此错误消息:
exception 'Guzzle\Http\Exception\CurlException' with message
'[curl] 23: Failed writing body (0 != 86) [url] https://email-smtp.eu-west-1.amazonaws.com/'
in C:\xampp\htdocs\myProject\protected\lib\vendor\guzzle\guzzle\src\Guzzle\Http\Curl\CurlMulti.php:338
有人知道如何解决这个错误吗?
cUrl 支持 SMTP,但 smtp://email-smtp.eu-west-1.amazonaws.com
抛出错误 [curl] 1: Protocol smtp not supported or disabled in libcurl [url] smtp://email-smtp.eu-west-1.amazonaws.com/
您没有使用有效的端点。
email-smtp.eu-west-1.amazonaws.com
是 SMTP 端点,而不是 HTTPS。 HTTPS 端点是 email.eu-west-1.amazonaws.com
.
http://docs.aws.amazon.com/general/latest/gr/rande.html#ses_region
- 将
https://email.{$region}.amazonaws.com
用作base_url
在此阶段,我收到错误消息:'用户 'arn:aws:iam::######:user/ebpush' 无权对资源执行 'ses:SendEmail' `arn:aws:ses:eu-west-1:447362101282:identity/verified@gmail.com'
- 添加 IAM > 群组 > 创建群组 > AmazonSESFullAccess
- 转到 IAM > 策略 > AmazonSESFullAccess > 附加 > ebPush
或
使用 PHPMailer 通过 email-smtp.{region}.amazonaws.com
连接,其中用户名是您的 SES 访问密钥,密码是您的 SES 密钥
您不需要在 AWS SDK 中为 PHP 显式设置 base_url/endpoint。设置区域将确保使用正确的端点。
我已经使用 PHP SDK 设置了 AWS Ses 服务:
$this->client = SesClient::factory([
'key' => $params['key'],
'secretKey' => $params['secret_key'],
'region' => 'eu-west-1',
'base_url' => 'https://email-smtp.eu-west-1.amazonaws.com',
]);
$this->client->sendEmail($this->params());
public function params() {
array(
'Source' => 'verified@gmail.com',
'Destination' => array(
'ToAddresses' => array('receiver@yahoo.com')
),
'Message' => array(
'Subject' => array(
'Data' => 'SES Testing',
'Charset' => 'UTF-8',
),
// Body is required
'Body' => array(
'Text' => array(
'Data' => 'My plain text email',
'Charset' => 'UTF-8',
),
'Html' => array(
'Data' => '<b>My HTML Email</b>',
'Charset' => 'UTF-8',
),
),
),
'ReplyToAddresses' => array( 'replyTo@email.com' ),
'ReturnPath' => 'bounce@email.com'
);
}
尝试发送电子邮件后,我收到此错误消息:
exception 'Guzzle\Http\Exception\CurlException' with message
'[curl] 23: Failed writing body (0 != 86) [url] https://email-smtp.eu-west-1.amazonaws.com/'
in C:\xampp\htdocs\myProject\protected\lib\vendor\guzzle\guzzle\src\Guzzle\Http\Curl\CurlMulti.php:338
有人知道如何解决这个错误吗?
cUrl 支持 SMTP,但 smtp://email-smtp.eu-west-1.amazonaws.com
抛出错误 [curl] 1: Protocol smtp not supported or disabled in libcurl [url] smtp://email-smtp.eu-west-1.amazonaws.com/
您没有使用有效的端点。
email-smtp.eu-west-1.amazonaws.com
是 SMTP 端点,而不是 HTTPS。 HTTPS 端点是 email.eu-west-1.amazonaws.com
.
http://docs.aws.amazon.com/general/latest/gr/rande.html#ses_region
- 将
https://email.{$region}.amazonaws.com
用作base_url
在此阶段,我收到错误消息:'用户 'arn:aws:iam::######:user/ebpush' 无权对资源执行 'ses:SendEmail' `arn:aws:ses:eu-west-1:447362101282:identity/verified@gmail.com' - 添加 IAM > 群组 > 创建群组 > AmazonSESFullAccess
- 转到 IAM > 策略 > AmazonSESFullAccess > 附加 > ebPush
或
使用 PHPMailer 通过 email-smtp.{region}.amazonaws.com
连接,其中用户名是您的 SES 访问密钥,密码是您的 SES 密钥
您不需要在 AWS SDK 中为 PHP 显式设置 base_url/endpoint。设置区域将确保使用正确的端点。