cjbeck71081 Posted January 11, 2007 Share Posted January 11, 2007 HelloI just posted earlier asking a question about a PHP handler that allowed the variables from a form to be put into an HTML table and then emailed to the user, and have the user see the table with items.I have it set up, and the email part of it is working, but instead of showing the table with the items inserted its showing the tags and codes of the HTML. I know its probably something simple.[code]<?php//variables taken from form$name=$_POST['name'];$car=$_POST['car'];$location=$_POST['location'];$color=$_POST['color'];//email to settings$to = "chris@epicri.com";$subject = "testemail";//email body$body = "<table width="400" border="0" cellpadding="0"> <tr> <td width="172">Name:</td> <td width="222">$name</td> </tr> <tr> <td>Location</td> <td>$location</td> </tr> <tr> <td>Car:</td> <td>$car<td> </tr> <tr> <td>Color:</td> <td>$color<td> </tr></table>";?><?php//Mailto settingsmail ($to, $subject, $body);header("http://www.cbeckserver.com/howworks.html");?>[/code]ThanksChris Quote Link to comment https://forums.phpfreaks.com/topic/33752-email-showing-html-tags-instead-of-table/ Share on other sites More sharing options...
obsidian Posted January 11, 2007 Share Posted January 11, 2007 By default, when you use the mail() function, emails are sent as text only. You have to adjust your headers and do some pretty fancy work to get HTML emails to work properly. With this in mind, I'd recommend you use something like [url=http://phpmailer.sourceforge.net/]PHPMailer[/url] or other open source mailer that has built-in support for HTML emails to handle it for you. Quote Link to comment https://forums.phpfreaks.com/topic/33752-email-showing-html-tags-instead-of-table/#findComment-158263 Share on other sites More sharing options...
cjbeck71081 Posted January 11, 2007 Author Share Posted January 11, 2007 IS there something other than the Mail() function that i can use to accomplish the same task?I looked into the PHP Mailer, and it says i have to install something on the server, i am using Godaddy.com to host the pages, and i dont have access to modify thier server, any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/33752-email-showing-html-tags-instead-of-table/#findComment-158286 Share on other sites More sharing options...
obsidian Posted January 11, 2007 Share Posted January 11, 2007 If you can use the mail() function on your server, you shouldn't have to install anything else for PHPMailer to work. I've used it many times on multiple different servers, and I've never had to install any additional modules to get it to work. If you'll download the class and simply follow the basic tutorials for using it, I think you'll find your modules are already in place.To answer the underlying question, no, there really isn't another way to get around it. Notice that the PHPMailer class still uses mail() to send the message, but it simply handles all your headers and additional parameters for you. Quote Link to comment https://forums.phpfreaks.com/topic/33752-email-showing-html-tags-instead-of-table/#findComment-158292 Share on other sites More sharing options...
HuggieBear Posted January 11, 2007 Share Posted January 11, 2007 Try this:[code]<?php//variables taken from form$name=$_POST['name'];$car=$_POST['car'];$location=$_POST['location'];$color=$_POST['color'];//email to settings$to = "chris@epicri.com";$subject = "testemail";$headers = "Content-Type: text/html\n\n"; // I added this row//email body (I've used heredoc syntax)$body = <<<HTML<table width="400" border="0" cellpadding="0"> <tr> <td width="172">Name:</td> <td width="222">$name</td> </tr> <tr> <td>Location</td> <td>$location</td> </tr> <tr> <td>Car:</td> <td>$car<td> </tr> <tr> <td>Color:</td> <td>$color<td> </tr></table>HTML;//Mailto settingsmail ($to, $subject, $body, $headers); // I've added the headers variable as the 4th parameter to mail()header("http://www.cbeckserver.com/howworks.html");?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33752-email-showing-html-tags-instead-of-table/#findComment-158309 Share on other sites More sharing options...
obsidian Posted January 11, 2007 Share Posted January 11, 2007 In addition to Huggie's code, you may want to change your MIME type header as well... FWIW. Quote Link to comment https://forums.phpfreaks.com/topic/33752-email-showing-html-tags-instead-of-table/#findComment-158313 Share on other sites More sharing options...
cjbeck71081 Posted January 11, 2007 Author Share Posted January 11, 2007 Sorry ive been kind of a pain in the pants, but i tried Huggies code, and the web page froze. I ran through and read the tutorial and set up the PHP Mailer with this code below. For some reason it still is not sending it in HTML, maybe someone can tell me where im going wrong. Im sure its in the BODY. Thanks[code]<?phprequire("class.phpmailer.php");$mail = new PHPMailer();$mail->IsSMTP(); // telling the class to use SMTP$mail->Host = "mail.epicri.com"; // SMTP server$mail->From = "chris@epicri.com";$mail->AddAddress("prov@epicri.com");$name=$_POST['name'];$mail->IsHTML(true); $mail->Subject = "first mailing";$mail->Body = "<table width="236" border="0" cellpadding="0"> <tr> <td width="83">Name:</td> <td width="311">$name</td> </tr></table>";$mail->WordWrap = 50;if(!$mail->Send()){ echo "Message was not sent"; echo "Mailer Error: " . $mail->ErrorInfo;}else{ echo "Message has been sent";}?> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/33752-email-showing-html-tags-instead-of-table/#findComment-158333 Share on other sites More sharing options...
HuggieBear Posted January 11, 2007 Share Posted January 11, 2007 You need to either escape your double quotes in the body or use a different syntax...Change this:[code]$mail->Body = "<table width="236" border="0" cellpadding="0"> <tr> <td width="83">Name:</td> <td width="311">$name</td> </tr></table>";[/code]To this:[code]$mail->Body = <<<HTML<table width="236" border="0" cellpadding="0"> <tr> <td width="83">Name:</td> <td width="311">$name</td> </tr></table>HTML;[/code]Or this:[code]$mail->Body = "<table width=\"236\" border=\"0\" cellpadding=\"0\"> <tr> <td width=\"83\">Name:</td> <td width=\"311\">$name</td> </tr></table>";[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33752-email-showing-html-tags-instead-of-table/#findComment-158336 Share on other sites More sharing options...
HuggieBear Posted January 11, 2007 Share Posted January 11, 2007 Also, the code I provided shouldn't cause your server to freeze. That's probably just coincidence.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33752-email-showing-html-tags-instead-of-table/#findComment-158339 Share on other sites More sharing options...
cjbeck71081 Posted January 11, 2007 Author Share Posted January 11, 2007 As i was waiting for a reply i read through everything and used logic, and all of your guys help and got it to work. Thank You very much, this is absolutely Perfect. Quote Link to comment https://forums.phpfreaks.com/topic/33752-email-showing-html-tags-instead-of-table/#findComment-158341 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.