php - 没有在 PHP 中使用基于 HTML 的电子邮件获取 CSS?

标签 php html css twitter-bootstrap email

我试图在电子邮件中接收基于循环生成的 HTML 表,但似乎我收到了电子邮件,但没有嵌入 CSS,因为我正在通过电子邮件传递 BootStrap 库 CSS 文件,但它根本没有收到任何 CSS。 .So I wondering that would be the problem...?

截图如下:

enter image description here

这是我的全部代码:

<?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);

?>

最佳答案

自 2016 年 9 月起,Gmail 接受嵌入式样式<style> 内的 CSS HTML 文档头部的标签。

这是对内联样式的补充,后者是以前在 Gmail 中应用 CSS 的唯一方式。

与此同时,Google 对外部样式的支持只字未提,这可能是您的 Bootstrap 样式无法加载的原因。

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

关于php - 没有在 PHP 中使用基于 HTML 的电子邮件获取 CSS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42536695/

相关文章:

php - 将图像存储在数据库中并检索它以 echo 作为 json

javascript - 在 Firefox 中上传大文件名时设计变形

javascript - 如何使用 HTML、CSS 和 JQuery 使菜单从移动设备的右侧滑动?

javascript - JSSOR slider - 如何更改这些属性?

javascript - 无法将从 api 提供的数据中检索到的背景图像添加到 div node.js

php - 在哪里实现工厂方法?

php - 模板化多语言网站的最有效方式

javascript - 当我打电话时尝试多次重复 ng-repeat

javascript - 使字体大小取决于 div 大小

java - css 子菜单在网站加载时保持刷新