By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,655 Members | 1,860 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,655 IT Pros & Developers. It's quick & easy.

Sending a HTML e-mail message

100+
P: 142
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]
Dec 11 '07 #1
Share this Question
Share on Google+
1 Reply


brettl
P: 41
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.
Dec 11 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.