无法在PHP中使用基于HTML的电子邮件获取CSS? [英] Not getting CSS with HTML Based Email In PHP?

查看:54
本文介绍了无法在PHP中使用基于HTML的电子邮件获取CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在电子邮件中接收基于循环的生成的HTML表,但是好像我在接收电子邮件,但没有嵌入CSS,因为我随电子邮件传递了BootStrap库CSS文件,但根本没有获得任何CSS.所以我想知道这是什么问题... ??

以下是屏幕截图:

这是我的整个代码:

 <?php$ message.='< link href ="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel ="stylesheet">';;$ message.='< table class ="table table-bordered">';$ message.='< thead>';$ message.='< tr>';;$ message.='< th ##//th>';;$ message.='< th>用户名</th>';;$ message.='< th>会话来自</th>';;$ message.='< th> Session Till</th>';;$ message.='< th&time; Uptime</th>';;$ message.='< th> Download</th>';;$ message.='< th&up;//th>';;$ message.='< th>总使用量</th>';;$ message.='</tr>';;$ message.='</thead>';$ message.='< tbody>';;函数human_filesize($ bytes,$ decimals = 2){$ factor = floor((strlen($ bytes)-1)/3);如果($ factor> 0)$ sz ='KMGT';return sprintf(%.{$ decimals} f",$ bytes/pow(1024,$ factor)).@ $ sz [$ factor-1].'B';}如果(isset($ _ GET)){$ user = $ _GET ["user"];}$ x = 1;$ handle = fopen($ user,"r");如果($ handle){while((($ line = fgets($ handle))!== false){$ split_data =(explode(",$ line));如果(in_array('customer = admin',$ split_data)){foreach(array_values($ split_data)as $ i => $ value){如果(strpos($ split_data [$ i],'user =')!== false){$ username = explode("=",$ split_data [$ i]);$ username = $ username [1];}}foreach(array_values($ split_data)as $ i => $ value){如果(strpos($ split_data [$ i],'from-time =')!== false){$ from_time = explode("=",$ split_data [$ i]);$ from_time = $ from_time [1];$ from_time = $ from_time.".$ split_data [$ i + 1];}}foreach(array_values($ split_data)as $ i => $ value){if(strpos($ split_data [$ i],'till-time =')!== false){$ till_time = explode("=",$ split_data [$ i]);$ till_time = $ till_time [1];$ till_time = $ till_time.".$ split_data [$ i + 1];}}foreach(array_values($ split_data)as $ i => $ value){如果(strpos($ split_data [$ i],'uptime =')!== false){$ uptime = explode("=",$ split_data [$ i]);$ uptime = $ uptime [1];$ download = explode("=",$ split_data [$ i + 1]);$ download = $ download [1];$ upload = explode("=",$ split_data [$ i + 2]);$ upload = $ upload [1];@ $ total_download + = $ download;@ $ total_upload + = $ upload;$ total_usage = $ total_download + $ total_upload;}}$ message.='< tr>';;$ message.='< th scope ="row">'.$ x.'</th>';;$ message.='< td>'.$ username.'</td>';;$ message.='< td>'.$ from_time.'</td>';;$ message.='< td>'.$ till_time.'</td>';;$ message.='< td>'.$ uptime.'</td>';;$ message.='< td>'.. human_filesize($ download,2).'</td>';;$ message.='< td>'.. human_filesize($ upload,2).'</td>';;$ message.='< td>'.human_filesize($ total_usage,2).'</td>';;$ message.='</tr>';;$ x = $ x + 1;}}fclose($ handle);}$ message.='</tbody>';$ message.='</table>';$ to ='nicefellow1234@gmail.com';$ subject ='网站更改要求';$ headers =发件人:".strip_tags($ _ POST ['req-email'])."\ r \ n";$ headers.="回复至:.strip_tags($ _ POST ['req-email'])."\ r \ n";$ headers.=" MIME版本:1.0 \ r \ n;$ headers.=内容类型:文本/html; charset = UTF-8 \ r \ n";mail($ to,$ subject,$ message,$ headers);?> 

解决方案

截至2016年9月,Gmail接受嵌入样式–HTML文档头部的< style> 标记内的CSS.

这是内嵌样式的补充,后者以前是在Gmail中应用CSS的唯一方法.

与此同时,Google对支持外部样式一无所知,这很可能就是您的Bootstrap样式无法加载的原因.

https://developers.google.com/gmail/design/

I am trying to receive a loop based generated HTML Table in email but seems like I am getting email but no CSS embedded with it as I am passing the BootStrap library CSS files with the email but it's not getting any CSS at all..So I am wondering that what would be the problem...??

Here is screenshot as :

Here is my whole code as :

<?php


$message .= '<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">';
$message .= '<table class="table table-bordered">';
  $message .= '<thead>';
    $message .= '<tr>';
    $message .= '<th>#</th>';
    $message .= '<th>Username</th>';
    $message .= '<th>Session From</th>';
    $message .= '<th>Session Till</th>';
    $message .= '<th>Uptime</th>';
    $message .= '<th>Download</th>';
    $message .= '<th>Upload</th>';
    $message .= '<th>Total Usage</th>';
    $message .= '</tr>';
  $message .= '</thead>';
  $message .= '<tbody>';


function human_filesize($bytes, $decimals = 2) {
    $factor = floor((strlen($bytes) - 1) / 3);
    if ($factor > 0) $sz = 'KMGT';
    return sprintf("%.{$decimals}f ", $bytes / pow(1024, $factor)) . @$sz[$factor - 1] . 'B';
}

if (isset($_GET)) {

  $user = $_GET["user"];
}

$x = 1;
$handle = fopen($user, "r");
if ($handle) {
    while (($line = fgets($handle)) !== false) {
        $split_data = (explode(" ",$line));
    if (in_array('customer=admin', $split_data)) {

foreach (array_values($split_data) as $i => $value) {
if (strpos($split_data[$i], 'user=') !== false) {
    $username = explode("=", $split_data[$i]);
    $username = $username[1];
}
}

foreach (array_values($split_data) as $i => $value) {
if (strpos($split_data[$i], 'from-time=') !== false) {
    $from_time = explode("=", $split_data[$i]);
    $from_time = $from_time[1];
    $from_time = $from_time." ".$split_data[$i+1];
} 
}

foreach (array_values($split_data) as $i => $value) {
if (strpos($split_data[$i], 'till-time=') !== false) {
    $till_time = explode("=", $split_data[$i]);
    $till_time = $till_time[1];
    $till_time = $till_time." ".$split_data[$i+1];
} 
}

foreach (array_values($split_data) as $i => $value) {
if (strpos($split_data[$i], 'uptime=') !== false) {
    $uptime = explode("=", $split_data[$i]);
    $uptime = $uptime[1];
    $download = explode("=", $split_data[$i+1]);
    $download = $download[1];
    $upload = explode("=", $split_data[$i+2]);
    $upload = $upload[1];
    @$total_download += $download; 
    @$total_upload += $upload;
    $total_usage = $total_download+$total_upload;
} 
}



$message .= '<tr>';
      $message .= '<th scope="row">'.$x.'</th>';
      $message .= '<td>'.$username.'</td>';
      $message .= '<td>'.$from_time.'</td>';
      $message .= '<td>'.$till_time.'</td>';
      $message .= '<td>'.$uptime.'</td>';
      $message .= '<td>'.human_filesize($download,2).'</td>';
      $message .= '<td>'.human_filesize($upload,2).'</td>';
      $message .= '<td>'.human_filesize($total_usage,2).'</td>';
    $message .= '</tr>';




$x=$x+1;

}
    }

    fclose($handle);
} 



$message .= '</tbody>';
$message .= '</table>';



$to = 'nicefellow1234@gmail.com';

$subject = 'Website Change Reqest';

$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";



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

?>

解决方案

As of September 2016, Gmail accepts embedded styles – CSS within <style> tags in the head section of HTML documents.

This is in addition to inline styles, which were previously the only way to apply CSS in Gmail.

At the same time, Google says nothing about support for external styles, which is likely why your Bootstrap styles are failing to load.

https://developers.google.com/gmail/design/

这篇关于无法在PHP中使用基于HTML的电子邮件获取CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆