Reputation: 85
Hello The Genious peoples.... I am trying to send a html mail using php everything in my php script looks to be correct but when I send the mail I recieve only plain text. This is the link url i am using to test the script http://www.mailme.netne.net you may check it here..
These are the codes in script:
<?php
require 'ErrorHandler.inc.php';
//.....set up a boundary to seperate the message..........
$boundary = '======'.md5(mt_rand(4,time())).'======';
$headers=array();
$headers[]='MIME-Version:1.0';
$headers[]='Content-type:multipart/alternative;boundary="'.$boundary.'"';
$headers[]='From: '.$_POST['from'];
$msg_body = 'This a is Multipart Message in MIME Format'."\n";
$msg_body .= '--'.$boundary."\n";
$msg_body .= 'Content-Type:text/html; charset="iso-8859-1"'."\n";
$msg_body .= 'Content-Transfer-Encoding:7bit'."\n\n";
$msg_body .=$_POST['message'] ."\n";
$msg_body .= '--'.$boundary."\n";
$msg_body .= 'Content-Type:text/plain; charset="iso-8859-1"'."\n";
$msg_body .= 'Content-Transfer-Encoding:7bit'."\n\n";
$msg_body .=strip_tags($_POST['message']) . "\n";
$msg_body .= '--'.$boundary.'--'."\n";
//======================send n test return value=======================
$success = mail($_POST['to'],$_POST['sub'],$msg_body,implode("\r\n",$headers)) ;
if($success)
{ echo "<strong>Your mail sent </strong>";}
else
{echo "<strong>Error Sending your mail..please try again later</strong>";}
echo " with following details:<br /><br />";
echo "<strong>From : </strong><em>" .$_POST['from']."<br />";
echo "<strong>To : </strong><em>".$_POST['to']. "<br/>";
echo "<strong>Subject : </strong><em>".$_POST['sub']."<br />";
echo "<strong>Message : </strong><em>".$msg_body."<br />";
?>
please help me ..I am trying since last 6 days..
Upvotes: 1
Views: 718
Reputation: 19879
You're adding header data to your message body:
$msg_body .= 'Content-Type:text/html; charset="iso-8859-1"'."\n";
$msg_body .= 'Content-Transfer-Encoding:7bit'."\n\n";
But you're not actually adding it to your headers like so:
$headers[] = 'Content-Type:text/html; charset="iso-8859-1"';
$headers[] = 'Content-Transfer-Encoding:7bit';
Try this:
<?php
require 'ErrorHandler.inc.php';
//.....set up a boundary to seperate the message..........
$boundary = '======'.md5(mt_rand(4,time())).'======';
$headers = array();
$headers[] = 'MIME-Version:1.0';
$headers[] = 'Content-type:multipart/alternative;boundary="'.$boundary.'"';
$headers[] = 'From: '.$_POST['from'];
$headers[] = 'Content-Type:text/html; charset="iso-8859-1"';
$headers[] = 'Content-Transfer-Encoding:7bit';
$msg_body = 'This a is Multipart Message in MIME Format'."\n";
$msg_body .= '--'.$boundary."\n";
$msg_body .= 'Content-Type:text/html; charset="iso-8859-1"'."\n";
$msg_body .= 'Content-Transfer-Encoding:7bit'."\n\n";
$msg_body .=$_POST['message'] ."\n";
$msg_body .= '--'.$boundary."\n";
$msg_body .= 'Content-Type:text/plain; charset="iso-8859-1"'."\n";
$msg_body .= 'Content-Transfer-Encoding:7bit'."\n\n";
$msg_body .=strip_tags($_POST['message']) . "\n";
$msg_body .= '--'.$boundary.'--'."\n";
//======================send n test return value=======================
$success = mail($_POST['to'],$_POST['sub'],$msg_body,implode("\r\n",$headers)) ;
if($success){
echo "<strong>Your mail sent </strong>";
}
else
{
echo "<strong>Error Sending your mail..please try again later</strong>";
}
echo " with following details:<br /><br />";
echo "<strong>From : </strong><em>" .$_POST['from']."<br />";
echo "<strong>To : </strong><em>".$_POST['to']. "<br/>";
echo "<strong>Subject : </strong><em>".$_POST['sub']."<br />";
echo "<strong>Message : </strong><em>".$msg_body."<br />";
?>
Upvotes: 1