【问题标题】:inline css not print in email when send email through php mail通过php邮件发送电子邮件时,内联css不会在电子邮件中打印
【发布时间】:2017-06-20 12:18:35
【问题描述】:

大家好,我想通过 php 中的电子邮件功能发送电子邮件,但在发送电子邮件和回显电子邮件正文之前,它可以很好地显示我需要的内容,但是在邮件中发送的这个正文部分 css 无法正常工作。我附上了两张图片(screenshorts),一张是在发送电子邮件之前,第二张是在我收到电子邮件之后,你会正确理解。

$body.= '<table border=1><tr><th>Branch</th>';
            for($i=0;$i<count($sections);$i++)
            {
                if($sections[$i]!="Task Admin")
                $body.="<th>".$sections[$i]."</th>";
            }
            $body.="</tr>";
            foreach($mainarrayparent as $keys => $value ) {
            $body.="<tr>";
                foreach($value as $keys1 => $getbranch ) { 
                    $getb = mysql_query("SELECT * from branch where id = '".$keys1."'");
                    $getbrow = mysql_fetch_assoc($getb);

                    $body.="<td>".$keys1." - ".$getbrow['name']."</td>";
                    foreach($getbranch as $keys3 => $getinner ) {
                            if($getinner==0){
                            $body.="<td style='background-color:#C6EFCE;'>".$getinner."</td>";
                            }else if($getinner!=0){
                            $body.="<td style='background-color:#FFC7CE;'>".$getinner."</td>";
                            }
                            else{
                                echo $keys3;

                            }
                    }   
                }
                $body.="</tr>";
            }
                $body.="</table>";
            //#C6EFCE
            echo $body;
            // die;

    //get overdue 


    $subject = "Acquisition Updates";
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    $headers .= 'From: <intranet@daylewis.net>' . "\r\n"; 
    $result = mail('jignesh.prajapati@daylewisplc.co.uk',$subject,$body,$headers);

【问题讨论】:

  • 请通过 Chrome 上的开发者工具或任何类似的工具通过 Inspect 元素检查这些单元格的 HTML。

标签: php html css email


【解决方案1】:

嗯,我可能知道这个。我记得有些电子邮件程序存在长文本问题。放置退货和切割可能会导致问题的 html。在其中一些循环的末尾添加 return 或 PHP_EOL 可能会有所帮助。

 foreach ($getbranch as $keys3 => $getinner) {
    if ($getinner == 0) {
        $body .= "<td style='background-color:#C6EFCE;'>" . $getinner . "</td>" . PHP_EOL;
    } else if ($getinner != 0) {
        $body .= "<td style='background-color:#FFC7CE;'>" . $getinner . "</td>" . PHP_EOL;
    } else {
        echo $keys3;

    }
}

【讨论】:

  • 谢谢,这是您“只需要知道”的内容之一,否则可能会导致问题。
猜你喜欢
  • 2012-02-04
  • 2014-05-30
  • 2014-08-17
  • 1970-01-01
  • 2011-05-21
  • 2011-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多