2012-05-04 30 views
4

我假设将文本/ html格式收入电子邮件的内容类型设置为客户端/用户计算机的默认字体样式和大小。用户梨邮件我将如何添加内容类型。我发送的所有示例仅显示添加MIME附件的内容类型。将内容类型添加到梨形邮件

另外,如果还有另一种方法可以使用户和收到的电子邮件默认给用户邮件客户端的字体样式和大小,我想知道。

想补充

$headers = "MIME-Version: 1.0\r\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 

当前的邮件代码

$from = "[email protected]"; 
$to = $SendTo; 
$subject = "Contact : " . $uxGlobalLocation; 
$body = $Bodycopy; 
$host = "mail.set.co"; 
$username = "[email protected]"; 
$password = "empty00"; 
$headers = array ('From' => $from, 
'To' => $to, 
'Subject' => $subject); 
$smtp = Mail::factory('smtp', 
array ('host' => $host, 
'auth' => true, 
'username' => $username, 
'password' => $password)); 
$mail = $smtp->send($to, $headers, $body); 
if (PEAR::isError($mail)) { 
echo("<p>" . $mail->getMessage() . "</p>"); 
} else { 
header ('Location: /'); 
exit(); 
} 

编辑可能的答案

$headers = array ('From' => $from, 
'To' => $to, 
'Subject' => $subject, 
'Content-Type' => 'text/html; charset=iso-8859-1', 
'MIME-Version' => '1.0'); 

回答

8

这工作。我花了很长时间才弄清楚$ headers数组中的最后一项必须有\ r \ n \ r \ n

<?php 
require_once "Mail.php"; 
$from = "Web Master <[email protected]>"; 
$replyto = "Education Dept. <[email protected]>"; 
$to = "<[email protected]>"; 
$subject = "Test email using PHP SMTP"; 
$body = "<p>Test HTML</p><p>This is a test email message</p>"; 

$host = "smtp.example.com"; 
$username = "[email protected]"; 
$password = "****************"; 

$headers = array ('From' => $from, 
    'To' => $to, 
    'Subject' => $subject, 
    'Reply-To' => $replyto, 
    'MIME-Version' => "1.0", 
    'Content-type' => "text/html; charset=iso-8859-1\r\n\r\n"); 

$smtp = Mail::factory('smtp', 
    array ('host' => $host, 
    'auth' => true, 
    'username' => $username, 
    'password' => $password)); 

$mail = $smtp->send($to, $headers, $body); 

if (PEAR::isError($mail)) { 
    echo("<p>" . $mail->getMessage() . "</p>"); 
} else { 
    echo("<p>Message successfully sent!</p>"); 
} 
?>