【发布时间】:2017-06-14 20:08:43
【问题描述】:
我是 AWS 的菜鸟。我今天配置了 AWS SES,现在我可以使用此代码向收件人发送电子邮件。
<?php
// Replace sender@example.com with your "From" address.
// This address must be verified with Amazon SES.
define('SENDER', 'sender email');
// Replace recipient@example.com with a "To" address. If your account
// is still in the sandbox, this address must be verified.
define('RECIPIENT', 'recipient email');
// Replace smtp_username with your Amazon SES SMTP user name.
define('USERNAME','my username');
// Replace smtp_password with your Amazon SES SMTP password.
define('PASSWORD','my password');
// If you're using Amazon SES in a region other than US West (Oregon),
// replace email-smtp.us-west-2.amazonaws.com with the Amazon SES SMTP
// endpoint in the appropriate region.
define('HOST', 'email-smtp.us-west-2.amazonaws.com');
// The port you will connect to on the Amazon SES SMTP endpoint.
define('PORT', '587');
// Other message information
define('SUBJECT','Hello from Driffle!');
define('BODY','Test Email');
require_once 'Mail.php';
$headers = array (
'From' => SENDER,
'To' => RECIPIENT,
'Subject' => SUBJECT);
$smtpParams = array (
'host' => HOST,
'port' => PORT,
'auth' => true,
'username' => USERNAME,
'password' => PASSWORD
);
// Create an SMTP client.
$mail = Mail::factory('smtp', $smtpParams);
// Send the email.
$result = $mail->send(RECIPIENT, $headers, BODY);
if (PEAR::isError($result)) {
echo("Email not sent. " .$result->getMessage() ."\n");
} else {
echo("Email sent!"."\n");
}
?>
但是当我尝试发送 html 格式的电子邮件时。输出电子邮件返回纯文本。正在寻找通过 Amazon SES 发送 html 电子邮件的解决方案。
【问题讨论】:
-
浏览指南 docs.aws.amazon.com/ses/latest/DeveloperGuide/… 并在 Google 上搜索您的标题。
-
@Fred-ii- 我只是按照该指南发送电子邮件,但我的问题是如何将它们作为带有图像和自定义字体的 HTML 发送。
-
使用完整的 url 使用 html 标记和图像源
-
您必须将图像和 css 内联到 html 元素,因为电子邮件提供商会阻止外部来源。如果这还不够复杂,那么每个电子邮件提供商都有自己的一套规则,这意味着一些元素在一个中起作用,而在另一个中不起作用。没有标准,因此请准备好为每个电子邮件提供商准备好模板。
-
我也在寻找这个解决方案。我相信 Mayank 的观点是,上面的示例发送文本电子邮件而不管标记。 SMTP 不知道内容是 HTML。我试过添加告诉它的标题,但它们会导致发送失败。我尝试过的其他几件事也失败了。这方面的 AWS 文档非常荒谬。
标签: php email amazon-web-services amazon-ses