Advanced Search

Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Sending HTML email

  1. #1
    Join Date
    Jul 2012
    Posts
    197
    Thanks
    55
    Thanked 3 Times in 3 Posts

    Default Sending HTML email

    I have following code in header for sending HTML emails.
    Code:
    	.
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers =  "Content-Transfer-Encoding: 8bit . "\r\n";

    My Issues are following


    I can't send html email with the above coding, all mails are getting in plain text..
    If the browser is not supporting HTML what is the alternate solution to display the message by stripping the HTML tags.
    You will know the truth, and the truth will set you free (John 8:32)(The truth is about the only begotten son of GOD.....When you feel you are alone for facing your problems, God will never leave you by your own You are important for God

  2. #2
    Join Date
    May 2013
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    You do like this to achieve what you want
    PHP Code:
    $headers "MIME-Version: 1.0" "\r\n";
    $to =$_POST['to'];
    $subject ='Job Opportunity @ m`brace';
    $message ='<head>
    <title>Untitled Document</title>
    </head>

    <body>your content</body>'
    ;
    $headers .= "Content-type:text/html;charset=iso-8859-1" "\r\n";

    // More headers
    $headers .= 'From:'.$_POST['from']."\r\n";

    mail($to,$subject,$message,$headers); 
    Do revert to me if there is any problem
    developerhusain
    Last edited by keyboard; 06-01-2013 at 01:25 AM. Reason: Format: Php Tags [php][/php]

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,623
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by letom View Post
    I have following code in header for sending HTML emails.
    Code:
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers =  "Content-Transfer-Encoding: 8bit . "\r\n";
    You've got a few syntax errors in that snippet:
    PHP Code:
    // missing single quote after "8bit"
    // also, you're assigning instead of concatenating (so your $headers will contain *only* this last line)
    $headers =  "Content-Transfer-Encoding: 8bit . "\r\n"; 
    PHP Code:
    // should be:
    $headers .=  "Content-Transfer-Encoding: 8bit" "\r\n"
    Also, I would highly recommend considering switching your encoding to UTF-8.

    *****
    Quote Originally Posted by letom View Post
    If the browser is not supporting HTML what is the alternate solution to display the message by stripping the HTML tags.
    I assume you mean the email client, not browsers.

    What I do is compose the email in plain text first, then, when necessary, add an HTML version )markdown is a nice way to do this). mail() is not a very good choice to send it, since it doesn't handle multipart messages conveniently. You might look at using Pear's Mail class instead.

    Keep in mind that email clients are generally "behind the times" when it comes to HTML support. Also, security settings and/or user preferences prohibit much of HTML - no scripts, usually no images, and a large subset of css won't work either. HTML emails are the one area where you still have to "design like 1999" - tables, inline styles, and so forth.
    Last edited by traq; 06-01-2013 at 04:41 PM. Reason: typo
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

  4. #4
    Join Date
    Jul 2012
    Posts
    197
    Thanks
    55
    Thanked 3 Times in 3 Posts

    Default

    Quote Originally Posted by developerhusain View Post
    You do like this to achieve what you want
    PHP Code:
    $headers "MIME-Version: 1.0" "\r\n";
    $to =$_POST['to'];
    $subject ='Job Opportunity @ m`brace';
    $message ='<head>
    <title>Untitled Document</title>
    </head>

    <body>your content</body>'
    ;
    $headers .= "Content-type:text/html;charset=iso-8859-1" "\r\n";

    // More headers
    $headers .= 'From:'.$_POST['from']."\r\n";

    mail($to,$subject,$message,$headers); 
    Do revert to me if there is any problem
    developerhusain
    Hi Husain

    Thanks for your kind advice.
    Your coding seems fine.., i have also some what related to this, but it not comes to the real solution of the problem but related to that..

    Regards
    Tom
    You will know the truth, and the truth will set you free (John 8:32)(The truth is about the only begotten son of GOD.....When you feel you are alone for facing your problems, God will never leave you by your own You are important for God

  5. #5
    Join Date
    Jul 2012
    Posts
    197
    Thanks
    55
    Thanked 3 Times in 3 Posts

    Default

    Quote Originally Posted by traq View Post
    You've got a few syntax errors in that snippet:
    PHP Code:
    // missing single quote after "8bit"
    // also, you're assigning instead of concatenating (so your $headers will contain *only* this last line)
    $headers =  "Content-Transfer-Encoding: 8bit . "\r\n"; 
    PHP Code:
    // should be:
    $headers .=  "Content-Transfer-Encoding: 8bit' . "\r\n"; 
    Also, I would highly recommend considering switching your encoding to UTF-8.

    *****
    I assume you mean the email client, not browsers.

    What I do is compose the email in plain text first, then, when necessary, add an HTML version )markdown is a nice way to do this). mail() is not a very good choice to send it, since it doesn't handle multipart messages conveniently. You might look at using Pear's Mail class instead.

    Keep in mind that email clients are generally "behind the times" when it comes to HTML support. Also, security settings and/or user preferences prohibit much of HTML - no scripts, usually no images, and a large subset of css won't work either. HTML emails are the one area where you still have to "design like 1999" - tables, inline styles, and so forth.
    Dear Adrain

    Thanks for your response and support.
    Iam not using any complicated html stuffs in messages neither images nor java scripts.
    only styling the layer as follows only.
    Code:
    <div style="border:1px solid #000000;font-family:arial">
    The mail is sending when a user register a account, so we have no option to choose html/text message before sending, it should identify itself and display HTML message or text message properly according to the working environment.

    Any solution some what related to <noscript> as noscript displays the content, if javscript is not supported, same way if html is not supported any solution to display the message properly
    You will know the truth, and the truth will set you free (John 8:32)(The truth is about the only begotten son of GOD.....When you feel you are alone for facing your problems, God will never leave you by your own You are important for God

  6. #6
    Join Date
    Jul 2012
    Posts
    197
    Thanks
    55
    Thanked 3 Times in 3 Posts

    Default

    HTML emails are the one area where you still have to "design like 1999" - tables, inline styles, and so forth.
    Why can't we use div instead of table and use inline styling in div as in the code of previous post?
    Last edited by letom; 06-01-2013 at 07:53 AM.
    You will know the truth, and the truth will set you free (John 8:32)(The truth is about the only begotten son of GOD.....When you feel you are alone for facing your problems, God will never leave you by your own You are important for God

  7. #7
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    1,881
    Thanks
    16
    Thanked 288 Times in 287 Posts
    Blog Entries
    4

    Default

    Adrian didn't mean that you can't use divs at all (in fact, a simple, one column layout for the sake of adding a border and font, like you have, should be perfectly ok, although you shouldn't rely on the border or font rendering 100% in all cases as it comes down to the settings/capabilities of the email client) but his advice is correct in a broader sense. For multi-column layouts and more advanced email layouts with logo/header/footer positioning, tables are just more predictable and offer a more 'stable' structure. Web-based email clients tend to fair a little better with div/CSS layouts, but desktop applications, such as MS Outlook and Lotus Notes, are less forgiving, especially with multi-column div floats (they'll just end up stacking on top of each other). Since you can't predict how your customers are accessing emails, this is one area where you should probably play it safe with the rigid, grid-like placement of (nested) tables.
    Focus on Function Web Design | Latest News RSS | Facebook | Twitter |
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps |
    The only limit to creativity is imagination: JemCon.org

  8. #8
    Join Date
    Jul 2012
    Posts
    197
    Thanks
    55
    Thanked 3 Times in 3 Posts

    Default

    Hi Beverley

    Thanks for your advice.

    Adrian didn't mean that you can't use divs at all
    YES, Just for understand the difference between using div and table.

    But i need a solution for displaying text version of same HTML message if the working environment is not supported HTML.

    Regards
    Tom
    Last edited by letom; 06-01-2013 at 10:13 AM.
    You will know the truth, and the truth will set you free (John 8:32)(The truth is about the only begotten son of GOD.....When you feel you are alone for facing your problems, God will never leave you by your own You are important for God

  9. #9
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    1,881
    Thanks
    16
    Thanked 288 Times in 287 Posts
    Blog Entries
    4

    Default

    That's fine - you can achieve that by using a "multipart/alternative" email which allows you to set a "boundary" that the email client uses to select from a plain text or HTML email (depending on how its setup and/or its capabilities).

    Here is a tutorial that should help with that: http://webcheatsheet.com/PHP/send_em...attachment.php
    Focus on Function Web Design | Latest News RSS | Facebook | Twitter |
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps |
    The only limit to creativity is imagination: JemCon.org

  10. The Following User Says Thank You to Beverleyh For This Useful Post:

    letom (06-01-2013)

  11. #10
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    1,881
    Thanks
    16
    Thanked 288 Times in 287 Posts
    Blog Entries
    4

    Default

    And here are some tutorials/tips/best practices for setting up HTML emails:

    http://24ways.org/2009/rock-solid-html-emails/

    http://kb.mailchimp.com/article/how-to-code-html-emails
    Focus on Function Web Design | Latest News RSS | Facebook | Twitter |
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps |
    The only limit to creativity is imagination: JemCon.org

  12. The Following User Says Thank You to Beverleyh For This Useful Post:

    letom (06-01-2013)

Similar Threads

  1. PHP Email Form not sending to email?
    By euphoriastudio in forum PHP
    Replies: 1
    Last Post: 02-14-2008, 07:04 PM
  2. sending mms to phone via email
    By davidjmorin in forum Looking for such a script or service
    Replies: 0
    Last Post: 01-04-2008, 09:36 PM
  3. PHP Only Sending To One Email
    By tomyknoker in forum PHP
    Replies: 11
    Last Post: 05-06-2007, 11:15 AM
  4. Test sending of email...
    By pavmoxo in forum PHP
    Replies: 0
    Last Post: 08-31-2006, 05:28 PM
  5. Sending an Email
    By Eclyps19 in forum JavaScript
    Replies: 3
    Last Post: 10-29-2005, 09:13 AM

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
  •