1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to use css while sending email using PHP mail()

Discussion in 'PHP' started by rahulephp, Sep 30, 2009.

  1. #1
    Hi there,

    I just want to use a couple of styles to manage the type and include the style sheet in the email,
    But after getting email in my Gmail inbox, It is showing email with all html code.(All tags & styles)

    Can anyone let me know, how to use css in email?

    Have a look on code bellow:

    $to=$data[2];
    $subject ="New Newsletter from couponguru.com";
    $headers = 'From: couponguru@gmail.com' . "\r\n" .
    'Reply-To: couponguru@gmail.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();


    $message ="<html>
    <body>
    <center>
    <table>
    <tr>
    <td>
    <div style='border:0px dotted gray;
    width:450px;
    padding:15px;
    margin-left:30px;
    float:left;
    font-weight: normal;
    font-size: 12px;
    color: #01165c;
    font-family: Verdana;
    text-decoration: none;'>
    <p>Dear $data[1]</p>
    <p>Welcome to www.couponguru.com Newsletter community.
    <br> Every month we identify articles from a variety of publications that we think you may find interesting and that may not have come to your
    attention. Some of these may pertain directly to you, while others are more general or perhaps just offbeat. You can pick or choose what you would like to see and as always we welcome your feedback.</p>
    <p>Please have a look on Newsletter below<p>
    <br>Best Regards,<br>CouponGuru.com
    </div>
    </td>
    </tr>
    </table>";

    mail($to, $subject, $message, $headers);
     
    rahulephp, Sep 30, 2009 IP
  2. krishmk

    krishmk Well-Known Member

    Messages:
    1,376
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    185
    #2
    You need to add the content-type header along with your script which would tell the browser to display it as html.

    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
     
    krishmk, Sep 30, 2009 IP
  3. rahulephp

    rahulephp Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks for reply from you.

    Yes i did that but didn't work even for this a simple one. Still it showing all html tags in gmail inbox.

    $to=$data[2];
    $subject ="New Newsletter from couponguru.com";
    $headers = 'From: ' . "\r\n" .
    'Reply-To: ' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    $message ="
    Dear subscriber,

    <h3 style='color: RED;'>
    This email confirms your purchase of a 30 day
    email support subscription. Please direct all
    requests to .</h3>

    Thank you,
    The Example.com support staff";

    mail($to, $subject, $message, $headers);
     
    rahulephp, Sep 30, 2009 IP
  4. prasanthmj

    prasanthmj Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    45
    #4
    update this way:
    
    $headers = 'From: couponguru@gmail.com' . "\r\n" .
    'Reply-To: couponguru@gmail.com' . "\r\n" .
    "X-Mailer: PHP/" . phpversion()."\r\n";
    
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    
    PHP:
    Also make the message complete HTML with <html><body> tags
     
    prasanthmj, Sep 30, 2009 IP
  5. adrevol

    adrevol Active Member

    Messages:
    124
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #5
    adrevol, Sep 30, 2009 IP
  6. rahulephp

    rahulephp Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yeah, it works,

    Thnaks a lot prasanthmj.
    I appreciate You.
     
    rahulephp, Sep 30, 2009 IP