我發送動態創建電子郵件正文中的HTML表,但在電子郵件中我收到的HTML代碼,而不是顯示錶。請幫幫我。 這是我的代碼。 我的服務器只支持發送電子郵件的代碼 $ email_message =「name:」.clean_string($ name)。「\ n」; 所以請幫我使用這段代碼。如何使用PHP發送包含HTML表格的電子郵件?
<?php
require ('class.phpmailer.php');
$name = @$_REQUEST['name'];
//$email = @$_REQUEST['email'];
$contact = @$_REQUEST['contact'];
$day = @$_REQUEST['day'];
$month = @$_REQUEST['month'];
$year = @$_REQUEST['year'];
$date_event = @$_REQUEST['date_event'];
$check = @$_REQUEST['check'];
$check_score = @$_REQUEST['check_score'];
$check_service = @$_REQUEST['check_service'];
$check_product = @$_REQUEST['check_product'];
$check_scheme = @$_REQUEST['check_scheme'];
$check_value = @$_REQUEST['check_value'];
$check_price = @$_REQUEST['check_price'];
$arr = array($year,$month,$day);
$doe_event = join("-",$arr);
[email protected]$_REQUEST['action'];
$today=getdate();
$gday="$today[mday]";
$gmonth="$today[mon]";
$gyear="$today[year]";
$ghour="$today[hours]";
$gminutes="$today[minutes]";
$gsecond="$today[seconds]";
$create_date="$gyear-$gmonth-$gday $ghour:$gminutes:$gsecond";
if($action=='add') {
$email_to = "your email";
$email_subject = "Message From Website";
$error_message = "";
$email_exp = "^[a-z .'-]+$";
$email_message = "<strong>Contact form</strong><br>";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
//All data In table mail
$headers = "From: $ContactPerson<[email protected]*******.co.in> \n";
$headers .= "Reply-To: $to \r\n";
$headers .= "X-Mailer: PHP/". phpversion();
$headers .= "X-Priority: 3 \n";
$headers .= "MIME-version: 1.0\n";
$headers .= "Content-Type: text/html; charset=UTF-8\n";
$email_message='<table cellspacing="0" cellpadding="0" border="1" align="center">
<tr>
<td bgcolor="#99CC00">Name ';
$email_message = "Quick enquiry detail.";
$email_message = " ".clean_string($name)."\n";'</td>
</tr>
</table>';
//$email_message .= clean_string($email);
//$email_message = "Quick enquiry detail.";
$email_message .= "name: ".clean_string($name)."\n";
$email_message .= "contact: ".clean_string($contact)."\n";
$email_message .= "doe: ".clean_string($doe_event)."\n";
if(isset($_REQUEST['check']) && count($_REQUEST['check']))
{
$recipient_email_addresses = array
(
);
foreach($_REQUEST['check'] as $value){
$email_message .= "services: ".clean_string($value)."\n";
};
}
// create email headers
$email_from="[email protected]*******.co.in";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$_REQUEST['email']."\r\n" .
'X-Mailer: PHP/' . phpversion();
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->FromName = $_REQUEST['name'];
$mail->Host = 'mail.*******.co.in';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]********.co.in';
$mail->Password = '********';
$mail->AddAddress("your email", "ADMIN");
$mail->Subject = "Contact Enquiry From www.********.co.in";
$mail->Body = $email_message;
if($mail->Send())
{
echo "<script>alert('Thank you for quick submit.') </script>";
echo "<script>location.replace('index.php?action=msgsent');</script>";
die;
}
else
{
echo "<script>alert('There was an error sending the message, Please try again.')</script>";
echo "<script>location.replace('index.php?action=msgerr');</script>";
die;
}
}
>
[如何在PHP中發送電子郵件正文中的HTML表?](http://stackoverflow.com/questions/6160320/how-to-send-html-table-in-email-body- in-php),直到前三句。 – outis
親愛的上帝,真是一團糟...... – veritas
你真的檢查過上面代碼生成的HTML是什麼嗎?我懷疑不... – DaveRandom