Results 1 to 16 of 16

Thread: How to email in HTML?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    447

    How to email in HTML?

    I have a code which emails in regular non-html format. How can I change to HTML?
    Attached Files Attached Files
    Compare bible texts (and other tools):
    TheWheelofGod

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: How to email in HTML?

    add a Content-type header:
    Code:
    Content-type: text/html;
    an example of doing this exists on the mail() function documentation.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    447

    Re: How to email in HTML?

    Quote Originally Posted by kows View Post
    add a Content-type header:
    Code:
    Content-type: text/html;
    an example of doing this exists on the mail() function documentation.
    Splendid!
    What is PHP_EOL supposed to do?
    Last edited by gilgalbiblewhee; Jul 29th, 2010 at 11:42 AM.
    Compare bible texts (and other tools):
    TheWheelofGod

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: How to email in HTML?

    PHP_EOL places an end-of-line character, which differs depending on the operating system (\r\n, or \n). this is a line break.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    447

    Re: How to email in HTML?

    Quote Originally Posted by kows View Post
    PHP_EOL places an end-of-line character, which differs depending on the operating system (\r\n, or \n). this is a line break.
    Ok I looked at the site and made some changes. It was working at first but now I'm not receiving any email even though when I print out the result in this page there seems to be no problem:

    edited this post:
    Ok. I tried an example. I removed my previous attachment and attached the following:

    I've been looking at:
    PHP Code:
    // 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.
    Attached Files Attached Files
    Last edited by gilgalbiblewhee; Jul 29th, 2010 at 06:40 PM.
    Compare bible texts (and other tools):
    TheWheelofGod

  6. #6
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: How to email in HTML?

    I'm not going to download your attachment. just copy and paste the code into your post.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    447

    Re: How to email in HTML?

    Quote Originally Posted by kows View Post
    I'm not going to download your attachment. just copy and paste the code into your post.
    PHP Code:
    <?php
    // multiple recipients
    $to  '[email protected]'.', '// note the comma
    $to .= '[email protected]';
    $from "[email protected]";
    // 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>
    Compare bible texts (and other tools):
    TheWheelofGod

  8. #8
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: How to email in HTML?

    you can't set your content-type to "text/css" -- that would set the content type to that of a CSS file, which you are not sending. use the header I showed you in an earlier post.

    if it isn't working, try using PEAR::Mail with PEAR::Mail_Mime instead.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    447

    Re: How to email in HTML?

    Quote Originally Posted by kows View Post
    you can't set your content-type to "text/css" -- that would set the content type to that of a CSS file, which you are not sending. use the header I showed you in an earlier post.

    if it isn't working, try using PEAR::Mail with PEAR::Mail_Mime instead.
    what about <style></style> but how then am i going to use for bold color font-size font-family...
    Compare bible texts (and other tools):
    TheWheelofGod

  10. #10
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: How to email in HTML?

    what do you mean how? you use CSS just like you would always use CSS. it's not like the way CSS works is changed when used in email versus on the web. some email clients don't properly support everything though.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    447

    Re: How to email in HTML?

    Quote Originally Posted by kows View Post
    what do you mean how? you use CSS just like you would always use CSS. it's not like the way CSS works is changed when used in email versus on the web. some email clients don't properly support everything though.
    I don't think Hotmail is supporting. I'm not getting the emails i send when there's css in it. ANd I think some tags aren't supported either. <b> seems ok though.

    And it's going in my junk folder and at times it won't even open.
    http://www.gbgrafix.com/thewheelofgo...ts/emailex.php
    I created a form with a get method and a textarea. Try it out for yourself.
    Last edited by gilgalbiblewhee; Jul 29th, 2010 at 09:54 PM.
    Compare bible texts (and other tools):
    TheWheelofGod

  12. #12
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: How to email in HTML?

    Possibly the email address you send 'From' does not belong to the SMTP server and thus is not verifiable.
    Spam filters will consider this junk.
    What you might want to do is use a no-reply address belonging to your domain.
    So $from = "[email protected]"; would be $from = "[email protected]";
    Try it.

    Also, can you post the source of one of those CSS using emails?
    Delete it. They just clutter threads anyway.

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    447

    Re: How to email in HTML?

    Quote Originally Posted by TheBigB View Post
    Possibly the email address you send 'From' does not belong to the SMTP server and thus is not verifiable.
    Spam filters will consider this junk.
    What you might want to do is use a no-reply address belonging to your domain.
    So $from = "[email protected]"; would be $from = "[email protected]";
    Try it.

    Also, can you post the source of one of those CSS using emails?
    Ok I added $from="[email protected]" but no change.

    It seems that emails accept some css attributes like color, weight, font-style but reject z-index, position...

    is there a function which informs you that the email is sent or not? I only find out if I receive it. And sometimes it takes hours.
    Last edited by gilgalbiblewhee; Jan 9th, 2011 at 03:31 AM.
    Compare bible texts (and other tools):
    TheWheelofGod

  14. #14
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: How to email in HTML?

    the mail() function returns a boolean value of whether or not the mail was sent successfully. this doesn't mean that your mail wasn't picked up in a spam filter. server load will have a lot to do with when mail is sent, too. I'd recommend using a more appropriate way of sending mail (rather than sendmail with PHP's mail() function) -- SMTP. you can use PEAR::Mail or other mailing libraries for this. this would also be a better better for sending complex mail with HTML or attachments.

  15. #15
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: How to email in HTML?

    There is no spec on HTML and CSS in emails and some people (like me) dislike receiving them. I suggest sticking to plain text. At the very least, you need to provide a plain text alternative, which can be done with multipart encoding.

    Also, headers are supposed to be separated by \r\n regardless of platform, but in practice I think this varies and \n is probably safer.

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    447

    Re: How to email in HTML?

    Quote Originally Posted by penagate View Post
    There is no spec on HTML and CSS in emails and some people (like me) dislike receiving them. I suggest sticking to plain text. At the very least, you need to provide a plain text alternative, which can be done with multipart encoding.

    Also, headers are supposed to be separated by \r\n regardless of platform, but in practice I think this varies and \n is probably safer.
    You're right. There are emails which cannot read html. Hotmail and yahoo read them but not others.
    Compare bible texts (and other tools):
    TheWheelofGod

Posting Permissions

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



Click Here to Expand Forum to Full Width