PHP経由でHTML電子メールを送信するコードがあります。それはテーブルを持っています。私はスクリーンショットで丸めて大胆にしたい。しかし、Gmailに到着した電子メールは、大胆に表示されず、「約」のクラスセレクタに適用されるべき他の変更も表示されません。PHP HTML電子メールクラスセレクタが動作しないGMAIL
私は、PHP、HTMLメールに自分のスタイルシートでクラスまたはIDセレクタを使用することはできますか?非効率であるため、私はインラインCSSを使いたくありません。私は体の中でそれらを使用しました。 ここにコードがあります。
$to = "[email protected], [email protected]"; //multiple recipients with comma separated
$subject = "Here is the subject"; //cannot contain newline characters
$message = "<h1>This is Heading H1</h1>";
$message .= "This is my <b>first</b> line of text.<br>This is my <b>second</b> line of text<br><br>"; //each line should be separated with (\n).
$message .= "<html>
<head>
<style>
body{
color:#000000;
background-color:#FFFFFF;
font-family:arial, verdana, sans-serif;
}
h1{
font-size:18px;
}
p{
font-size:12px;
}
table{
background-color:#efefef;
border-style:solid;
border-width:1px;
border-color:#999999;
}
th{
background-color:#cccccc;
font-weight:bold;
padding:5px;
}
td{
padding:5px;
}
td.about{
font-family:courier, courier-new, serif;
font-weight:bold;
}
</style>
</head>
<body>
<table>
<tr>
<th> About </th>
<th> Description </th>
</tr>
<tr>
<td class=\"about\"> Name </td>
<td> Andreas </td>
</tr>
<tr>
<td class=\"about\"> Address </td>
<td> Germany </td>
</tr>
<tr>
<td class=\"about\"> Message </td>
<td> I like your 8 day tour package. What are the rates? </td>
</tr>
</table>
</body>
</html>
";
//headers like From, Cc, Bcc, Reply-to, Date ???????????
//$header = "From:[email protected] \r\n";
$header = "From: RXXXXX CXXXXX <[email protected]> \r\n"; //additional headers should be separated with (\r\n)
//$header .= "Cc: [email protected] \r\n";
//$header .= "Bcc: [email protected] \r\n";
//always specify MIME version, content type, and character set when sending HTML email
$header .= "MIME-Version: 1.0 \r\n";
$header .= "Content-type:text/html;charset=UTF-8 \r\n";
//$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; //////////////////////////////Pls Delete later
$retval = mail($to, $subject, $message, $header);
if($retval == true){
echo "Message sent successfully";
}
else{
echo "Message could not be sent!";
}
あなたのCSSで '.about {...'のみを試しましたか? –
@PedroLobito先生、これらすべてのバリエーションを確認しました:.ab {...、td.ab {...。しかしgmailはクラス名を特定しません。しかし、Yahooは正しく表示されます –
簡単な答えは、HTML電子メールの場合、異なる電子メールクライアント間で一貫性を得るためにCSSをインライン化する必要があることです。 HTML電子メールは、各電子メールクライアントが異なる方法でCSSと書式をレンダリングするため、悪名を抱いています。 –