向Pear Mail添加Content-type

时间:2012-05-04 21:34:05

标签: php

我假设将text / 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');

1 个答案:

答案 0 :(得分:8)

这很有效。我花了很长时间才弄清楚$ 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>");
}
?>