为什么不在使用mail()php发送邮件到gmail时在电子邮件中显示类css?
我通过此代码测试发送电子邮件,以便通过电子邮件将其显示在电子邮件中
但是,当我测试通过此代码发送电子邮件时,它会像这样显示它。
它没有显示class ='按钮'和hotmail一样,我该怎么做?
<?PHP
include("connect.php");
$to = "some_mail@gmail.com";
$subject = "test email";
$message = "
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<style type='text/css'>
.button{
color: #a7a7a2;
background: green;
padding: 2px 14px;
border-radius: 10px;
}
</style>
</head>
<body style='margin: 0; padding: 0;font-family: \"Helvetica Neue\", Helvetica, Arial, sans-serif;'>
<table align='center' style='margin:auto;'>
<tbody>
<tr>
<td class='button'>
<a href='test.php' target='_blank' style='padding: 11px 0px; display:block; text-decoration:none; color:#000; font-size:16px; text-align:center; font-family:arial; font-weight:bold'>TEST BUTTON</a>
</td>
</tr>
</tbody>
</table>
</body>
</html>
";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: EXAMPLE <noreply@example.com>' . "\r\n";
$headers .= 'Return-Path: return@example.com' . "\r\n";
mail($to, $subject, $message, $headers, '-freturn@example.com');
?>
答案 0 :(得分:1)
Gmail不支持head标记中的嵌入式css。但你可以试试这个:
<html>
<body style='margin: 0; padding: 0;font-family: \"Helvetica Neue\", Helvetica, Arial, sans-serif;'>
<table align='center' style='margin:auto;'>
<tbody>
<tr>
<style scoped>
td {
color: #a7a7a2;
background: green;
padding: 2px 14px;
border-radius: 10px;
}
</style>
<td>
<a href='test.php' target='_blank' style='padding: 11px 0px; display:block; text-decoration:none; color:#000; font-size:16px; text-align:center; font-family:arial; font-weight:bold'>TEST BUTTON</a>
</td>
</tr>
</tbody>
</table>
</body>
</html>
以上内容对儿童td
应用了一种风格,而不是整个文档。