HTML email through SES SMTP interface - PEAR

雨燕双飞 提交于 2019-12-25 08:09:26

问题


I wish to send HTML emails. I tried using mime.php but could not get it working. Below is my working text email code:

<?php
$subject="hello-test";
$body="<html><body><h1>message body</h1></body></html>";

$em_arr=array("email@example.com");
foreach ($em_arr as $to_address)
{

require_once '/usr/local/share/pear/Mail.php';

$headers = array (
  'Content-Type:text/html;charset=UTF-8',
  'From' => 'Test <test@example.com>',
  'To' => $to_address,
  'Subject' => $subject);

$smtpParams = array (
  'host' => '<smtp host address>',
  'port' => 587,
  'auth' => true,
  'username' => '<uname>',
  'password' => '<password>'
);

 // Create an SMTP client.
$mail = Mail::factory('smtp', $smtpParams);

// Send the email.
$result = $mail->send($to_address, $headers, $body);

if (PEAR::isError($result)) {
  echo("Email not sent. " .$result->getMessage() ."\n");
} else {
  echo("Email sent to ".$to_address."\n");
}
}
?>

Please let me know how can I send HTML emails.


回答1:


I had to replace the Content header line to:

'Content-Type' => "text/html; charset=UTF-8",

That was the mistake above. It is working fine now.



来源:https://stackoverflow.com/questions/39785613/html-email-through-ses-smtp-interface-pear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!