我正在使用PHP邮件程序将在线表单直接发送到电子邮件。我想编辑这样的表格:
$message = '<p>The following request was sent from: '</p>;
$message .= '<p>Name: '.$name.'</p><br />';
$message .= '<p>Phone: '.$phone.'</p><br />';
$message .= '<p>Email: '.$email.'</p><br />';
但是,在我收到的电子邮件中,我收到<p>
,<br />
等。不是我想要的格式,而是实际的HTML。它一直对我有用,然后我意识到我正在使用股票PHP邮件功能。不确定PHP邮件程序是否有不同的参数或者我是否只是在这里丢失了一小部分?
我在哪里设置text / html的标题?
$mail = new PHPMailer();
$mail -> IsSMTP();
$mail -> Host = "---";
$mail -> Port = 25;
$mail -> SMTPAuth = false;
$mail -> Username = EMAIL_USER;
$mail -> Password = EMAIL_PASS;
$mail -> FromName = $from_name;
$mail -> From = $from;
$mail -> Subject = $subject;
$mail -> Body = $message;
$mail -> AddAddress("---");
$result = $mail -> Send();
答案 0 :(得分:46)
答案 1 :(得分:31)
mail()
函数为text/plain
。在mail()
标题中,将content-type
更改为text/html
然后尝试。
<?php
$body = "<html>\n";
$body .= "<body style=\"font-family:Verdana, Verdana, Geneva, sans-serif; font-size:12px; color:#666666;\">\n";
$body = $message;
$body .= "</body>\n";
$body .= "</html>\n";
$headers = "From: My site<noreply@example.com>\r\n";
$headers .= "Reply-To: info@example.com\r\n";
$headers .= "Return-Path: info@example.com\r\n";
$headers .= "X-Mailer: Drupal\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
return mail($recipient, $subject, $message, $headers);
?>
您需要设置IsHTML(true)
:
$mail->IsHTML(true);