gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 12:41:55 25 4
gpt4 key购买 nike

当用户忘记使用此 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com