4

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

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

想补充

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

当前邮件代码

$from = "sys@test.com";
$to = $SendTo;
$subject = "Contact : " . $uxGlobalLocation;
$body = $Bodycopy;
$host = "mail.set.co";
$username = "donotreply@set.co";
$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');
4

1 回答 1

9

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

<?php
require_once "Mail.php";
$from = "Web Master <master@example.com>";
$replyto = "Education Dept. <education@example.com>";
$to = "<mytest@example.com>";
$subject = "Test email using PHP SMTP";
$body = "<p>Test HTML</p><p>This is a test email message</p>";

$host = "smtp.example.com";
$username = "master@example.com";
$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>");
}
?>
于 2012-12-19T21:57:27.333 回答