If you are making an email software then you must know how to make email templates and send with proper headers in stylish format not a plain email with only text. In
PHP with mail() function you can send a simple email but but there is some headers which make it more flexible you can attached files format it in
HTML and many more. I am going to explain you how to make an
HTML email and give you a
demo and script to download.
|
<?php
mail($to, $subject, $message, $headers);
?>
|
Send HTML email with PHP needs same method as normal email.
|
<?php
$to = "huzoorbux@gmail.com";
$from = 'info@phpgang.com';
$headers = "From: " . strip_tags($from) . "\r\n";
$headers .= "Reply-To: ". strip_tags($from) . "\r\n";
$headers .= "CC: info@phpgang.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
?>
|
To send HTML email you have to add headers which is optional by default where we pass Content-Type type declaration telling mail services that parse this email as HTML.
The headers give us lots of important functions to our emails like file attachment, content type etc.
Use HTML tags for design
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<?php
$message = '<html><body>';
$message .= '<table width="100%"; rules="all" style="border:1px solid #3A5896;" cellpadding="10">';
$message .= "<tr><td><img src='http://www.phpgang.com/wp-content/uploads/gang.jpg' alt='PHP Gang' /></td></tr>";
$message .= "<tr><td colspan=2>Dear \$Name,<br /><br />We thank you for subscribe phpgang.com you are now in phpgang download list you can download any source package from our site.</td></tr>";
$message .= "<tr><td colspan=2 font='colr:#999999;'><I>PHPGang.com<br>Solve your problem. :)</I></td></tr>";
$message .= "</table>";
$message .= "</body></html>";
?>
|
Now your emails look nicer this email is directly coming to you in formatted style to be easy to eyes.
No comments:
Post a Comment