20

我正在使用 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();
4

2 回答 2

47

在 PHP 邮件程序中,您需要在下面设置

$mail->IsHTML(true);

注意:$mail表示您的 PHPMailer 对象。

参考链接:PHPMailer

于 2012-12-09T17:53:22.580 回答
33

默认情况下,PHPmail()函数是text/plain.

在您的mail()标题中,更改content-typetext/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); 
?>

PHP 邮件程序:

您需要设置IsHTML(true)

$mail->IsHTML(true);
于 2012-12-09T17:50:48.753 回答