Connecting Tech Pros Worldwide Forums | Help | Site Map

Sending a HTML e-mail message

Familiar Sight
 
Join Date: Oct 2006
Posts: 142
#1: Dec 11 '07
Hi, I tried to get a script or something to send my e-mial in HTML format becasuse I want to add tables to line up certain text.

How do I get the e-mail to go from plain text to HTML?

Thanks

[PHP]
<?php
$con = mysql_connect("******","******","****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}mysql_select_db("total", $con);$result = mysql_query("SELECT * FROM email");while($row = mysql_fetch_array($result))
{
$to = "$row[a1]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";

}mysql_close($con);
?>

[/PHP]

brettl's Avatar
Member
 
Join Date: Sep 2007
Posts: 38
#2: Dec 11 '07

re: Sending a HTML e-mail message


You'll have to add the following to your headers variable:
Expand|Select|Wrap|Line Numbers
  1. $headers  = 'MIME-Version: 1.0' . "\r\n";
  2. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  3.  
Then just build your html in your message variable like so:
Expand|Select|Wrap|Line Numbers
  1. $message = '<html><head><title>Some Title Here</title></head>';
  2. $message .= '<body><p>So and so sent you this url';
  3. $message .= '<a href="http://www.somedomain.com/url.html" title="URL Title">Url Title</a><br/>';
  4. $message .= 'And a message : <br/>';
  5. $message .= $mailMessage.'</p></body></html>';
  6.  
Hope this helps. Let me know.
Reply