Jump to content

Email showing HTML tags instead of Table


cjbeck71081

Recommended Posts

Hello

I 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 settings
mail ($to, $subject, $body);
header("http://www.cbeckserver.com/howworks.html");
?>
[/code]

Thanks
Chris
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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 settings
mail ($to, $subject, $body, $headers); // I've added the headers variable as the 4th parameter to mail()
header("http://www.cbeckserver.com/howworks.html");
?>[/code]

Regards
Huggie
Link to comment
Share on other sites

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]<?php
require("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]

Link to comment
Share on other sites

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]

Regards
Huggie
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.