Categories

Tools

bitdefender

1&1 Web Hosting

Send HTML email with PHP


PHP provides programmers the mail() function to send email messages. With the addition of a few instructions you can send messages in HTML format.

<?php
// Recipient of the email
$recipient = "name@company.com";

//Subject of message
$subject = "HTML mail message from PHP!";

//HTML Message
$message = '
<html>
<body bgcolor="#dddddd" text="#888888">
<div align="center">
	<table width="500" border="0" cellspacing="1" cellpadding="1" bgcolor="#ffffff">
		<tr> 
			<td>
			Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
			sed diam nonummy nibh euismod tincidunt ut laoreet dolore
			magna aliquam erat volutpat.
			<br />
			Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
			sed diam nonummy nibh euismod tincidunt ut laoreet dolore
			magna aliquam erat volutpat.
			</td>
			</tr>
			<tr bgcolor="#EFEFEF"> 
			<td bgcolor="#EFEFEF" >Receive this email because it is subscribed to our newsletter</td>
		</tr>
	</table>
</div>
</body>
</html>
';

// We must define the Content-type header
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

if(mail($recipient, $subject, $message, $headers))
	echo( 'Message sent successfully' );
else
	echo( 'It was not possible to send the message' );
?>
Posted in PHP by MdmSoft

If our work has been of help, you can help us with a small donation...
Our programmers will thank you!



All information contained in this web site are the property of MdmSoft. The information is provided "as is", MdmSoft will not be liable for any misuse of the code contained in these pages, nor can it be for inaccuracies, grammatical errors or other factors that may have caused damage or lost earnings. MdmSoft is not responsible for the content of comments posted by users.
The examples in this area have the educational and demonstration purposes only, and may be copied only for your reference, but cannot be used for commercial purposes, or for any other purpose, without the express written consent of MdmSoft.
MdmSoft also reserves the right to change, without notice, to your liking this web site, the pages and its sections, and may suspend temporarily or definitely the various services included on this site.
While using this site, you agree to have read and accepted our Terms of Service and Privacy Policy.