当我收到来自带有php处理程序的html表单的电子邮件时,如何将文本加粗和斜体


How to make text bold and italic when I receive email from an html form with php handler

我想在收到电子邮件时用粗体显示"新订单!"和"所有用户输入"数据。还想把"每个客户…公司"变成斜体。

$to = $myemail; 
    $email_subject = "Order from: $name";
    $email_body = "New order!".
    "'n Below are the details:'n Name: $name 'n Email: $email_address 'n Phone Number: $phone_number 'n Item Code: $item_code 'n Payment Mode: $payment_mode 'n Address: $address 'n 'n Every customer expects quality services from your company";

PHP邮件函数有4个参数:to、subject、message和headers。

mail($to, $subject, $message, $headers);

要启用HTML消息(这将允许您使用<strong><em>等标记分别创建粗体和斜体文本),只需在$headers参数中添加以下行即可。

$headers = "Content-Type: text/html; charset=ISO-8859-1'r'n";

标头还可用于向"收件人"和"发件人"字段添加格式,以及包括CC和BCC:

$headers = "From: From Name<" . strip_tags($from_email) . ">'r'n";
$headers .= "Reply-To: Reply-To Name<". strip_tags($from_email) . ">'r'n";
$headers .= "To: ". strip_tags($to_email) ."'r'n";
$headers .= "CC: susan@example.com'r'n";
$headers .= "MIME-Version: 1.0'r'n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1'r'n";

*注意:这个特殊的例子来自这里
*另请注意:mail()函数的第四个参数($headers)是完全可选的,但为了启用HTML电子邮件(而不是默认的纯文本电子邮件),您必须在$headers参数中指定它。

使用此代码在PHP邮件中使用HTML

$header = "MIME-Version: 1.0'r'n"; 
        $header .= "Content-type: text/html; charset: utf8'r'n";
        $mail->IsHTML(true);