gpt4 book ai didi

php - AWS SES SMTP 电子邮件有效。 AWS SES API 不发送电子邮件

转载 作者:行者123 更新时间:2023-12-05 06:15:33 26 4
gpt4 key购买 nike

我在具有共享托管平台(不在 AWS 上)的网站上使用 AWS SES

当我使用 SMTP 发送电子邮件时,它运行良好。当我尝试调用和使用 API 时,没有发送电子邮件,也没有收到错误消息。

我想使用 API 而不是 SMTP 有两个原因1) 根据 Amazon 的说法,API 更快。2) 我的一封交易电子邮件提醒客户登录和/或支付他们的账户。 SMTP 不能向超过 50 个发送电子邮件(如果我没记错的话)。因此,我需要调用 SendRawEmail。

请帮助我发送电子邮件和实现 SendRawEmail 的代码

这是我的代码: require ('PHPMailer/PHPMailerAutoload.php');

use Aws\Ses\SesClient;
use Aws\Exception\AwsException;


// Create an SesClient. Change the value of the region parameter if you're
// using an AWS Region other than US West (Oregon). Change the value of the
// profile parameter if you want to use a profile in your credentials file
// other than the default.
$SesClient = new SesClient([
'profile' => 'default',
'version' => '2010-12-01',
'region' => 'eu-central-1'
]);

// Replace sender@example.com with your "From" address.
// This address must be verified with Amazon SES.
$sender_email = 'info@mydomain.com';

// Replace these sample addresses with the addresses of your recipients. If
// your account is still in the sandbox, these addresses must be verified.
$recipient_emails = ['info@example.com'];

// Specify a configuration set. If you do not want to use a configuration
// set, comment the following variable, and the
// 'ConfigurationSetName' => $configuration_set argument below.
//$configuration_set = 'ConfigSet';

$subject = 'Amazon SES test (AWS SDK for PHP)';
$plaintext_body = 'This email was sent with Amazon SES using the AWS SDK for PHP.' ;
$html_body = '<h1>AWS Amazon Simple Email Service Test Email</h1>'.
'<p>This email was sent with <a href="https://aws.amazon.com/ses/">'.
'Amazon SES</a> using the <a href="https://aws.amazon.com/sdk-for-php/">'.
'AWS SDK for PHP</a>.</p>';
$char_set = 'UTF-8';

try {
$result = $SesClient->sendEmail([
'Destination' => [
'ToAddresses' => $recipient_emails,
],
'ReplyToAddresses' => [$sender_email],
'Source' => $sender_email,
'Message' => [
'Body' => [
'Html' => [
'Charset' => $char_set,
'Data' => $html_body,
],
'Text' => [
'Charset' => $char_set,
'Data' => $plaintext_body,
],
],
'Subject' => [
'Charset' => $char_set,
'Data' => $subject,
],
],
// If you aren't using a configuration set, comment or delete the
// following line
'ConfigurationSetName' => $configuration_set,
]);
$messageId = $result['MessageId'];
echo("Email sent! Message ID: $messageId"."\n");
} catch (AwsException $e) {
// output error message if fails
echo $e->getMessage();
echo("The email was not sent. Error message: ".$e->getAwsErrorMessage()."\n");
echo "\n";
}

?>

最佳答案

检查您的错误日志。我有同样的问题:

需要'AWS/aws-autoloader.php';

对于其他 SDK 用途(例如 API 调用),您可能需要创建一个 .aws 文件夹以包含 credentials

关于php - AWS SES SMTP 电子邮件有效。 AWS SES API 不发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62459865/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com