简体   繁体   English

HTML邮件显示错误

[英]HTML mail displayed wrong

When I send html message through an mail sending it will break the design in mail account. 当我通过邮件发送html消息时,它将破坏邮件帐户中的设计。 The code is below: 代码如下:

<?php
$center_part2 = "";
$mail_ID = "exmaple.gmail.com";
$subject = "UnTouched Ticket Notification";
$headers = "From: example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$part = '<html><body>';
$part .= '<div style="background-color: #EEEEEE;border-bottom: 1px solid #DCDCDC;padding: 10px 10px 20px;width: 500px; float:left;font-size:12px;font-weight:bold;">';
$part1 = '<div style="width:500px;">';
$part1 .= '<div style="width:500px;background-color:#eeeeee;padding: 10px 0 20px;border-bottom:1px solid #dcdcdc;">';  
$part1 .= '<div style="width:450px;background-color:#eeeeee;padding: 10px 0 20px;border-bottom:1px solid #dcdcdc; height:auto; float:left;font-size:12px;margin-left:50px; font-weight:bold;">';
$part3 = '</div></div></div>';
$part3 .= '</body></html>';
$center_part = 'You have opened '.$inr.' tickets . But the following tickets are not updated yet ,';
$center_part2.="<div style='width:345px;color:#000000;font-size:12px;margin-left:75px; font-weight:bold; height:auto; margin-top:10px;'>"; 
    for ($k=1; $k<=70; $k++){

       $new.="<p>Ticket &#35;".$K." Last Updated  ".$K." days ".$K." hours  ago &#33;</p>";
    }
    $center_part2.=$new."</div>";
    if($mail_ID){
        $message = "";
        $center_part1 = 'Dear Admin ,'; 
        $message = $part.$center_part1.$part1.$center_part.$center_part2.$part3;
        mail($mail_ID, $subject, $message, $headers);
    }
?>

When I opened the gmail I get the mail like this: 当我打开gmail时,我收到这样的邮件:

屏幕截图

So what is the problem in my code? 那么我的代码有什么问题呢?

I'll post my comment as an answer as davidethell suggested, in case anyone else lands here with the same problem. 我将按照davidethell的建议将评论发表为答案,以防其他人遇到同样的问题。

The display issue was due to the <div> tags having float:left and a fixed width, causing them to become stacked side by side where the width permitted. 显示问题归因于<div>标签具有float:left和固定宽度,导致它们在允许宽度的位置并排堆叠。

The ! ! problem where random ! 问题在哪里随机! are inserted into the email content is due to exceeding the max characters per line. 插入电子邮件内容是由于超出了每行的最大字符数。 Keeping each line under 512 characters will resolve this. 保持每行少于512个字符可解决此问题。 Use a \\n to break up the content as required. 根据需要使用\\n拆分内容。

您尚未关闭以下代码的<div>

$part .= '<div style="background-color: #EEEEEE;border-bottom: 1px solid #DCDCDC;padding: 10px 10px 20px;width: 500px; float:left;font-size:12px;font-weight:bold;">';

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

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