PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Kingo
Forum Contributor
Posts: 146 Joined: Thu Jun 03, 2004 9:38 am
Post
by Kingo » Thu Oct 21, 2004 7:38 am
Hello,
I'm trying to send the Email of an feed back form and I want the receipent to recieve the mail in an HTML format. I mean I'm trying to display the results in the table format. But with the below code, the reciepents email is showing the HTML code for the table rather than the table. ANy help is really appreciated.
Code: Select all
html>
<head>
<title>feed</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align="center">
<p><font color="#0000FF" size="3" face="Arial, Helvetica, sans-serif"><strong>Feed
Back PHP Page</strong></font><font color="#0000FF" face="Arial, Helvetica, sans-serif"><strong></strong></font>
</p>
</div>
<?php
$t1 = $_POST["tf1"];
$t2 = $_POST["tf2"];
$t3 = $_POST["tf3"];
$message="";
$mailsubject = " Feedback from customer";
$mailbody = " <html><head></head><body>The user entered the following:\n";
$mailbody.="<table width="50%"><tr><td> The Users Name is " .$t1."\n</td></tr>";
$mailbody.=" <tr><td>The Users Emp# is " .$t2."\n</td></tr>";
$mailbody.=" <tr><td>The Users Phone is " .$t3."\n</td></tr></table>";
$mailbody.=" Have a nice day</body></html>";
$email ="makhalid143@yahoo.com";
$result = mail($email,$mailsubject,$mailbody);
if ( $result)
{
echo "<p> EMail sent to Khalid</p>";
}
else
{
echo " <p>Email could not be sent</p>";
}
?>
</body>
</html>
m3mn0n
PHP Evangelist
Posts: 3548 Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada
Post
by m3mn0n » Thu Oct 21, 2004 7:45 am
You're not sending any additional headers so the e-mail is being sent as the default type, which is plaintext.
If you define additional headers you can customize the e-mail type so it sends as HTML.
More info: [php_man]mail()[/php_man] & [google]php mail html email script[/google]
Kingo
Forum Contributor
Posts: 146 Joined: Thu Jun 03, 2004 9:38 am
Post
by Kingo » Thu Oct 21, 2004 7:54 am
I used the following.. But It still doesnt work
Code: Select all
<?php
$t1 = $_POST["tf1"];
$t2 = $_POST["tf2"];
$t3 = $_POST["tf3"];
$headers = "From: webserver@localhost\r\n";
//specify MIME version 1.0
$headers .= "MIME-Version: 1.0\r\n";
//unique boundary
$boundary = uniqid("HTMLDEMO");
//tell e-mail client this e-mail contains//alternate versions
$headers .= "Content-Type: multipart/alternative" .
"; boundary = $boundary\r\n\r\n";
//message to people with clients who don't
//understand MIME
$headers .= "This is a MIME encoded message.\r\n\r\n";
//plain text version of message
$headers .= "--$boundary\r\n" .
"Content-Type: text/plain; charset=ISO-8859-1\r\n" .
"Content-Transfer-Encoding: base64\r\n\r\n";
$headers .= chunk_split(base64_encode("This is the plain text version!"));
//HTML version of message
$headers .= "--$boundary\r\n" .
"Content-Type: text/html; charset=ISO-8859-1\r\n" .
"Content-Transfer-Encoding: base64\r\n\r\n";
$headers .= chunk_split(base64_encode("This the <b>HTML</b> version!"));
$message="";
$mailsubject = " Feedback from customer";
$mailbody = " <html><head></head><body>The user entered the following:\n";
$mailbody.="<table width="50%"><tr><td> The Users Name is " .$t1."\n</td></tr>";
$mailbody.=" <tr><td>The Users Emp# is " .$t2."\n</td></tr>";
$mailbody.=" <tr><td>The Users Phone is " .$t3."\n</td></tr></table>";
$mailbody.=" Have a nice day</body></html>";
$email ="makhalid143@yahoo.com";
$result = mail($email,$mailsubject,$mailbody,$headers);
if ( $result)
{
echo "<p> EMail sent to Khalid</p>";
}
else
{
echo " <p>Email could not be sent</p>";
}
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Oct 21, 2004 6:27 pm
since you are sending a double type message, you need to put the content you want to send in the headers. Not in the message.. I believe.