在phpmailer中添加HTML格式 [英] Add HTML formatting in phpmailer
本文介绍了在phpmailer中添加HTML格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用PHP邮件程序直接将在线表单发送到电子邮件.我想编辑这样的表格:
I am using PHP mailer to send an online form directly to email. I want to edit the form like this:
$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邮件程序是否具有不同的参数,或者我是否在这里遗漏了小信息?
However, in the email I receive back, I get the <p>
, <br />
, etc. Not the formatting I want, but the actual HTML. It has always worked for me, then I realized I was using the stock PHP mail function. not sure if PHP mailer has different parameters OR if I just missing small here?
我在哪里设置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();
推荐答案
默认情况下,PHP mail()
函数为text/plain
.
在mail()
标头中,将content-type
更改为text/html
并尝试.
By default, the PHP mail()
function is text/plain
.
In your mail()
headers, change the content-type
to text/html
and try.
<?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);
?>
PHP Mailer:
您需要设置IsHTML(true)
:
$mail->IsHTML(true);
这篇关于在phpmailer中添加HTML格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文