Jimbly2
Jimbly2

Reputation: 227

HTML formatted email does not display correctly

I'm still struggling with this mail script - I'm now getting all the marked up html through rather than seeing it as rendered html if that makes sense?

<?php
$mailheader .= "MIME-Version: 1.0\r\n";
$mailHeader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$formcontent .="<table border='1'>";
foreach ($_POST as $field=>$value)
{
    $formcontent.="<tr>";
    $formcontent .= "<td>$field:</td> <td>$value</td>";
    $formcontent.="</tr>";
}
$formcontent .= '<tr><td>User-Agent: </td><td>'.$_SERVER['HTTP_USER_AGENT'].'</td>';
$formcontent .="</table>";


$recipient = "info@*******.com";
$subject = "Event feedback form";
$mailheader = "From: web.form@*******-events.co.uk\r\n";
$mailheader .= "Reply-To: $email\r\n";
$mailHeader .= "Content-type: text/html; charset=iso-8859-1\r\n";


mail($recipient, $subject, $formcontent, $mailheader) or die("Failure!");
header("location:http://www.******-events.co.uk");
?>

Upvotes: 2

Views: 1487

Answers (3)

Jimbly2
Jimbly2

Reputation: 227

I'd missed these:

$formcontent = '<html><body>';

Thanks for everyone's time and input though Jim

Upvotes: 0

Max Hudson
Max Hudson

Reputation: 10206

Follow php's documentation:

You'll need html tags

 <?php
// multiple recipients
$to  = '[email protected]' . ', '; // note the comma
$to .= '[email protected]';

// subject
$subject = 'Birthday Reminders for August';

// message
$message = '
<html>
<head>
  <title>Birthday Reminders for August</title>
</head>
<body>
  <p>Here are the birthdays upcoming in August!</p>
  <table>
    <tr>
      <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
    </tr>
    <tr>
      <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
    </tr>
    <tr>
      <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
    </tr>
  </table>
</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?>

Upvotes: 1

napolux
napolux

Reputation: 16074

I'd rather use a PHP class as PHPMailer for HTML emails. And btw I will add the full HTML document tags (html, head, body, etc...) for the mail body.

Upvotes: 0

Related Questions