mongmongmong seesee mongmongmong seesee - 2 years ago 161
PHP Question

Why not show class css in email when using mail() php send mail to gmail?

Why not show class css in email when using mail() php send mail to gmail ?

I test send email by this code to hotmail it's show like this in email

enter image description here

But when i test send email by this code to gmail it's show like this.

enter image description here

It's not show class='button' as same as hotmail how can i do that ?

<?PHP
include("connect.php");
$to = "[email protected]";
$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: \&quot;Helvetica Neue\&quot;, 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 <[email protected]>' . "\r\n";
$headers .= 'Return-Path: [email protected]' . "\r\n";
mail($to, $subject, $message, $headers, '[email protected]');
?>

Answer Source

Gmail does not support embedded css in the head tag. But you can try this:

<html>
        <body style='margin: 0; padding: 0;font-family: \&quot;Helvetica Neue\&quot;, 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>

The above applies a style to the child td and not the whole document.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download