How to email in CSS (HTML)?

Discussion in 'PHP' started by gilgalbiblewheel, Jul 29, 2010.

  1. #1
    I've been looking at:
    // 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";
    PHP:
    I want to use css, if possible in my newsletters to email. But I can't find any info on this.

    Here's the full code:
    <?php
    // multiple recipients
    $to  = 'youremail@hotmail.com'.', '; // note the comma
    $to .= 'your2ndemail@hotmail.com';
    $from = "your3rdemail@hotmail.com";
    // subject
    $subject = 'Another Birthday Reminders for August';
    
    // message
    $message = '
    <html>
    <head>
      <title>Birthday Reminders for August</title>
    </head>
    <body>
      <p>Here are the birthdays upcoming in August!</p>
      <table>
        <tr>
          <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
        </tr>
        <tr>
          <td style=\"font-weight: bold;\">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>
    ';//<font size="3" color="red"></font>
    
    // 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";
    
    // Additional headers
    //$headers .= 'To: ' . $to . "\r\n";
    $headers .= 'From: ' . $from . "\r\n";
    //$headers .= 'Cc: ' . "\r\n";
    //$headers .= 'Bcc: ' . "\r\n";
    
    // Mail it
    mail($to, $subject, $message, $headers);
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
        <div style="text-align: center;">
            <b>Thank you <br /><?php 
    		echo "From: " . $_REQUEST['youremail']."<br />\n";
    		echo "Emails sent to: ".$_REQUEST['theiremail']."<br />\n";
    		echo "Subject: ".$_REQUEST['subject']."<br />\n";
    		echo "Passage: ".$_REQUEST['passage']."<br />\n";
    		?></b><br />
            Your message has been sent
            <p><a href="<?php echo $baseURL; ?>">Click here to continue</a></p>
        </div>
    </body>
    </html>
    PHP:
     
    gilgalbiblewheel, Jul 29, 2010 IP
  2. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #2
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    PHP:
    Try it out for yourself
    http://www.gbgrafix.com/thewheelofgod/twotexts/emailex.php
    Yahoo seems more tolerant than hotmail. But it's annoying that it goes in the junk folder. How does digitalpoint do it that the notifications go to the inbox?
     
    gilgalbiblewheel, Jul 29, 2010 IP
  3. manzar

    manzar Peon

    Messages:
    111
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Well firstly you need to create the email in the same format as you would any other HTML document. I.e. having a head, and body section.

    In the head you should declare your stylesheets using include the css style inline.

    And with images, you'll need to declare them with absolute links, or by including the links as attachments.
     
    manzar, Jul 29, 2010 IP
  4. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #4
    I was sending it to my email and some are delayed by 12 hours. All end up in my junk. I'm confused what works and what doesn't.
     
    gilgalbiblewheel, Jul 30, 2010 IP