Sending HTML e-mail with PHP
Posted in: Business,Programming
It’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:
-
-
<?php
-
// reciever, sender, subject
-
$to = "me@here.com";
-
$from = "you@there.com";
-
$subject = "Hello HTML e-mail World!";
-
-
// message body
-
$message = "<body>
-
<strong>This is my first HTML e-mail I sent via PHP</strong>
-
<font color=\"red\">Great!</font>
-
<a href=\"http://example.com\"> example.com</a>";
-
-
// headers defining HTML format
-
$headers = "MIME-Version: 1.0\r\n";
-
$headers .= "Content-type: text/html; charset=utf-8\r\n";
-
$headers .= "From: $from\r\n";
-
-
// sending e-mail
-
?>
-
Return to: Sending HTML e-mail with PHP
Social Web