php - 如何将 CSS 附加到 PHP 中的 mail() 方法?

标签 php html css email

当用户忘记使用此 php 代码的密码时,我会向用户发送一封电子邮件:

<?php
//OTHER CODE BEFORE ALL THIS

$to = "$useremail";
$from = "forgotpassword@mysite.com";
$headers ="From: $from\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \n";

$subject = 'Temporary Password';
$msg = '<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Message</title>
</head>
<body>
<div>
  <div>Temporary Password</div>
  <p>Hello<b> '.$f.'</b>,</p>
  <p>You indicated that you forgot your login password. We can generate a temporary password for you to log in with, then once logged in you can change your password to anything you like.</p>
  <p>After you click the link below your password to login will be:</p>
  <p><b>'.$tempPass.'</b></p>
  <div style="margin: 0px auto;
text-align: center;">
    <p><a style="   background: #f3c1e6;
    background: -webkit-gradient(linear, 0 0, 0 bottom, from(#f3c1e6), to(#de66c0));
    background: -moz-linear-gradient(#f3c1e6, #de66c0);
    background: linear-gradient(#f3c1e6, #de66c0);
    border: solid 1px #cd5daf;
    border-bottom: solid 3px #ce5eb0;
    box-shadow: inset 0 0 0 1px #e998d3;
    color: #fff;
    text-shadow: 0 1px 0 #ce5eb0;
    zoom: 1;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    -ms-border-radius: 5px;
    -o-border-radius: 5px;
    border-radius: 5px;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    -webkit-box-shadow: 0 -1px 0 rgba(255,255,255,0.1) inset;
    -moz-box-shadow: 0 -1px 0 rgba(255,255,255,0.1) inset;
    box-shadow: 0 -1px 0 rgba(255,255,255,0.1) inset;
    der-radius: 5px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -moz-inline-stack;
    display: inline-block;
    vertical-align: middle;
    font-weight: bold;
    padding: 12px 15px;
    font-size: 14px;
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    cursor: pointer;" href="http://www.bragmouth.com/forgot_pass.php?u='.$u.'&p='.$hashTempPass.'">Click Here to Apply</a></p>
  </div>
</div>
</body>
</html>
';
if(mail($to,$subject,$msg,$headers)) {
echo 'true';
exit();
} else {
echo 'false';
exit();
}
    } else {
        echo 'false';
    }
    exit();
}
?>

我的问题是我无法通过内部或外部样式表向此电子邮件添加任何 CSS。但是,我可以将内联样式添加到 HTML 中的任何标记。我需要将 Content-type 更改为 text/css 还是我可以有两种内容类型?

此外,我无法在雅虎邮件中显示渐变(这可能是他们的错)。我可以让它们显示在谷歌邮件中,链接除外(这就是我发布链接样式的原因)。这也是谷歌的错吗?这一切都可以通过附加样式表来解决吗?

最佳答案

我建议不要在您的电子邮件 html 中使用 css 样式。 Outlook 用他们的 CSS 做一些奇怪的事情(他们甚至改变你的 HTML 来添加他们的自定义类)而且我相信 Gmail 去掉了 head 标签。

我使用一个工具将 CSS 转换为内联样式:

Css Inliner

关于php - 如何将 CSS 附加到 PHP 中的 mail() 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26793076/

相关文章:

html - 如何水平和垂直显示多个复选框 css

javascript - $(document).on ('click' 在 Chrome 中不起作用

jquery - 在触控设备上导航

css - 缓存背景图片

html - 相对于同样响应的容器的绝对位置

css - 正确的标签/输入格式的好处

javascript - 内联 HTML javascript 事件将转义引号解释为结束引号

php - 处理查询/多个查询的多个结果时的最佳实践?

php - 如何在 Laravel 模型中使用多个工具

php - 用户登录后从数据库中显示网页上合适的信息