2016-09-30 65 views
0

我希望發送HTML電子郵件。我嘗試使用mime.php,但無法使其工作。以下是我的工作文本電子郵件代碼:通過SES SMTP接口的HTML電子郵件 - PEAR

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

$em_arr=array("[email protected]"); 
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 <[email protected]>', 
    '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"); 
} 
} 
?> 

請讓我知道如何發送HTML電子郵件。

回答

1

我不得不把Content標題行替換到:

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

這是上面的錯誤。現在工作正常。