Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add background color to html email sent with php mail()

Im trying to add background color to this html email.

Ive tried putting in

  • <script> tags with css code inside

  • bgcolor in body tags

  • and a css style sheet

    All of which didnt work. Ive read that it could possibly be the provider (gmail) I'm sending these tests to, but there has to be a way.

All the ways I have tested on a separate .html file which has all changed to what I wanted. I just cant get it to in the actual email. I am using the mail() in php.

    $message = "
    <html>
    <head>
    <title>Rate Your Experience</title>
    </head>
    <body bgcolor = '#0000FF'>
    <center>
    
    <p>
        <h2>How well did '$recipient' do?</h2>
        <h4>Vacancy Title: '$vac_title'</h4>
        <h4>Vacancy ID: '$vac_id'</h4>
    </P>
    </center>
    <center>
        <table>
        <tr>
        <td><h3>we are built on sharing your review with other people who may also want to use this service.</h3></td>
        </tr>
        <tr>
        <td><h3>Please take a minute to reflect on the level of service youve received.</h3></td>
        </tr>
        <tr>
        <td><h3>Your review is public - to other employers registered with Ahoy Employ.</h3></td>
        </tr>
        <tr>
        <td><h3>Should you have any concerns that you would prefer to share in private, please email us at [email protected] and quote the Vacancy ID shown above.</h3></td>
        </tr>
        </table>
    </center>
    </body>
    </html>
    ";

    // Always set content-type when sending HTML email
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

    // More headers
    $headers .= 'From: <[email protected]>' . "\r\n";

    mail($to,$subject,$message,$headers);
like image 396
Jermayne Williams Avatar asked Dec 01 '25 05:12

Jermayne Williams


1 Answers

Try Like this:

  <body style="background-color:#cfcfcf";>
like image 104
Omar Avatar answered Dec 02 '25 18:12

Omar