簡體   English   中英

如何在PHP中使用Amazon SES發送HTML電子郵件

[英]How to send html email using Amazon SES in PHP

我是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電子郵件的解決方案。

找到了。 我做錯了一點,但這行得通...

添加以下標頭:

'Mime-Version'=>'1.0','Content-Type'=>'text / html; 字符集= “ISO-8859-1””,

然后以HTML標記的形式提交正文(開始時請盡可能簡單-不必一定是“頁面”)。

BH

在$ headers中添加了content-type。 對我有用

require_once 'Mail.php';

$headers = array (
'Content-Type' => "text/html; charset=UTF-8",  // <- add this line 
'From' => SENDER,
'To' => RECIPIENT,
'Subject' => SUBJECT);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM