Reputation: 111
I am trying to send an mail to an email account. And in the content part of the email/ message part of the email i want to include an html file. Below is my code for php file:
<?php
$to = "[email protected]";
$from = "[email protected]";
$subject = "This is the subject";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Put your HTML here
$message = file_get_contents('index.html');
$headers = "From: $from \r\n".
"MIME-Version: 1.0" . "\r\n" .
"Content-type: text/html; charset=UTF-8" . "\r\n";
mail($to,$subject,$message,$header);
?>
But the problem is, when the mail is sent, it shows the whole HTML code in the email content. i dont want the code to be seen. But proper content. Can anybody help me with this please?
Upvotes: 0
Views: 52
Reputation: 1485
Change
mail($to,$subject,$message,$header);
to
mail($to,$subject,$message,$headers);
HTML Message send example :
// 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);
Reference : (PHP 4, PHP 5) mail — Send mail
Upvotes: 2