Add HTML formatting in phpmailer

*爱你&永不变心* 提交于 2019-11-27 13:36:39

By default, the PHP mail() function is text/plain.

In your mail() headers, change the content-type to text/html and try.

Example:

<?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:

You need to set IsHTML(true):

$mail->IsHTML(true);

In PHP mailer, you need to set below

$mail->IsHTML(true);

Note: $mail means your PHPMailer object.

Reference Link: PHPMailer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!