如何在PHP中使用AmazonSES发送html电子邮件

如何在PHP中使用AmazonSES发送html电子邮件,php,email,amazon-web-services,amazon-ses,Php,Email,Amazon Web Services,Amazon Ses,我在美国焊接学会是个彻头彻尾的笨蛋。我今天配置了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

我在美国焊接学会是个彻头彻尾的笨蛋。我今天配置了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");
}

?>

找到了它。我做错了一点,但这是有效的

添加以下标题:

“Mime版本”=>“1.0”, '内容类型'=>'文本/html;charset=“ISO-8859-1”

然后以HTML标记的形式提交正文(一开始就尽可能简单,不一定是“页面”)


bh

在$headers中添加了内容类型。它对我有用

require_once 'Mail.php';

$headers = array (
'Content-Type' => "text/html; charset=UTF-8",  // <- add this line 
'From' => SENDER,
'To' => RECIPIENT,
'Subject' => SUBJECT);
require_once'Mail.php';
$headers=数组(
'内容类型'=>“text/html;charset=UTF-8”,//发件人,
'收件人'=>收件人,
“主题”=>主题);

浏览指南并用谷歌搜索你的标题。@Fred ii-我遵循指南只是为了发送电子邮件,但我的问题是如何使用图像和自定义字体将它们作为HTML发送。使用完整URL使用HTML标记和图像源你必须将图像和css内联到HTML元素,因为电子邮件提供商会阻止外部源。如果这还不够复杂,那么每个电子邮件提供商都有自己的一套规则,这意味着一些元素在1中工作,而在另一个中则不工作。没有标准,所以请准备好为每个电子邮件提供商准备一个模板。我也在搜索此解决方案。。我认为,Mayank的观点是,上面的示例发送文本电子邮件,而不考虑标记。SMTP不知道内容是HTML。我已经尝试添加了这样的标题,但是它们导致发送失败。我尝试过的其他几件事也失败了。美国焊接学会(AWS)关于这一点的文件竟然没有。