What is this? From this page you can use the Social Web links to save Sending HTML e-mail with PHP to a social bookmarking site, or the E-mail form to send a link via e-mail.

Social Web

E-mail

E-mail It
February 19, 2009

Sending HTML e-mail with PHP

Posted in: Business,Programming

emailIt’s really hard for me to read unformatted e-mails, and it’s getting annoying when I recieve some important information and loose my eyes on scanning bunch of text in search for text I need to read.

I was also one of those programmers who didn’t “found time” to format those notification e-mails sent to webshop customers, but after some time I realized what I was missing:

  • attractive looking e-mail newsletters to attrack customers to buy more
  • simplifying user registration with easy to read next registration process step
  • etc. 

Looking from a programming perspective, sending HTML e-mail from PHP is just as easy as sending plain text e-mails – using mail() function + defining a simple parameter in a message header.

Here’s a PHP sample code:

  1.  
  2. <?php
  3. // reciever, sender, subject
  4. $to = "me@here.com";
  5. $from = "you@there.com";
  6. $subject = "Hello HTML e-mail World!";
  7.  
  8. // message body
  9. $message = "<body>
  10. <strong>This is my first HTML e-mail I sent via PHP</strong>
  11. <font color=\"red\">Great!</font>
  12. <a href=\"http://example.com\"> example.com</a>";
  13.  
  14. // headers defining HTML format
  15. $headers = "MIME-Version: 1.0\r\n";
  16. $headers .= "Content-type: text/html; charset=utf-8\r\n";
  17. $headers .= "From: $from\r\n";
  18.  
  19. // sending e-mail
  20. mail($to, $subject, $message, $headers);
  21. ?>
  22.  

 


Return to: Sending HTML e-mail with PHP