简体   繁体   English

PHP邮件HTML格式无法正常工作

[英]PHP mail HTML formatting not working

I wrote a code to send PHP mail using HTML format. 我写了一个代码来使用HTML格式发送PHP邮件。

  $email_message = '
        <html>
        <body>
            <table>
                <tr>
                    <td colspan="2"><div style="color: #3300FF; font-size: 18px;">text</div></tr></table></body></html>';

    $mail_to = 'xxx@xxxxxxxx.com'; 
    $mail_subject = 'Booking';
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers = 'From: <xxx@xxxxxx.com>';        
    mail($mail_to, $mail_subject, $email_message, $headers);

but this output look like this: 但是这个输出看起来像这样:

<html>
<body>
<table>
<tr>
<td colspan="2"><div style="color: #3300FF; font-size: 18px;">

display all html code without formatting, could any one help me, I can't find the error 显示所有没有格式化的HTML代码,任何人都可以帮助我,我找不到错误

You are overwriting $header variable here 你在这里覆盖了$header变量

$headers = "From: <xxx@xxxxxx.com>";   

That should be 那应该是

$headers .= "From: <xxx@xxxxxx.com>";   // Add the concatenate operator 

the last line of the header i think your header you forgot to concatenate 标题的最后一行我认为你忘了连接你的标题

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = 'From: <xxx@xxxxxx.com>'; 

Although @shankar pointed out, but I think thats not the issue because first variable should be initialise in order to concatenate it. 虽然@shankar指出,但我认为这不是问题,因为第一个变量应该初始化以便连接它。

Here is the link for proper html email 这是适当的HTML电子邮件的链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM