SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to email in CSS (HTML)?

    I've been looking at:
    Code PHP:
    // To send HTML mail, the Content-type header must be set
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    //$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    //$headers .= 'Content-type: text/css; charset=iso-8859-1' . "\r\n";
    $headers .= 'Content-type: text/css;' . "\r\n";
    I want to use css, if possible in my newsletters to email. But I can't find any info on this.
    Compare bible texts (and other tools):
    TheWheelofGod

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    ... use a standard <style></style> tag to define the CSS like you would in any normal HTML file, and then send the mail as type html...

  3. #3
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    ... use a standard <style></style> tag to define the CSS like you would in any normal HTML file, and then send the mail as type html...
    Oh And how does that work? <style></style> How do I put font, bold, size...
    Compare bible texts (and other tools):
    TheWheelofGod

  4. #4
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gilgalbiblewheel View Post
    Oh And how does that work? <style></style> How do I put font, bold, size...
    PHP Code:
    $headers  'MIME-Version: 1.0' "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n"
    Try it out for yourself
    http://www.gbgrafix.com/thewheelofgo...ts/emailex.php
    Yahoo seems more tolerant than hotmail. But it's annoying that it goes in the junk folder. How does Sitepoint do it that the notifications go to the inbox?
    Compare bible texts (and other tools):
    TheWheelofGod

  5. #5
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)

  6. #6
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    That's the css <style> tag. What do you want me not to use inline?
    Compare bible texts (and other tools):
    TheWheelofGod

  7. #7
    SitePoint Enthusiast
    Join Date
    Jul 2010
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi
    Below is the sample code.
    PHP Code:
    <?php 
    // multiple recipients
    $to 'test@sitepoint.com';

    // subject
    $subject 'Testing';

    //you can also include the source of the css file but must place the full URL with domain
    //for example "http://sitepoint.com/test.css"
    $css.='<style type="text/css">
            .test{
                font-size:12px;
                color:red;
            }
            </style>'
    ;
    // message
    $message '
    <html>
    <head>
      <title>Birthday Reminders for August</title>
      '
    .$css.'
    </head>
    <body>
      <p  class="test">Here are the birthdays upcoming in August!</p>
      <table>
        <tr>
          <th  class="test">Person</th><th>Day</th><th>Month</th><th>Year</th>
        </tr>
        <tr>
          <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
        </tr>
        <tr>
          <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
        </tr>
      </table>
    </body>
    </html>
    '
    ;

    // To send HTML mail, the Content-type header must be set
    $headers  'MIME-Version: 1.0' "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";

    // Additional headers
    $headers .= 'To: Mary <test@sitepoint.com>' "\r\n";
    $headers .= 'From: Sitepoint <sitepoint@sitepoint.com>' "\r\n";

    // Mail it
    mail($to$subject$message$headers);
    ?>

  8. #8
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n"
    =
    PHP Code:
    $headers .= "Content-type: text/html;\r\nCharset=iso-8859-1\r\n"
    Strip out the unnecessary To: header (That's handled by your $to variable)

    Try that, see if that fixes it...

  9. #9
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are learning how to send HTML emails from PHP, then I would recommend to study some articles like:
    http://articles.sitepoint.com/articl...nced-email-php
    http://css-tricks.com/sending-nice-html-email-with-php/
    http://www.programmersheaven.com/mb/...sending-email/

    Otherwise, for professional purpose, it is really better to use PHPMailer to send any kinds of emails. You don't have to do anything yourself. Just prepare your HTML and send it through PHPMailer class.

    Download:
    http://phpmailer.worxware.com/index.php?pg=sf&p=dl

    Examples:
    http://phpmailer.worxware.com/index.php?pg=examples
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •