0

mail()を使用してメールを送信すると、メールでHTMLコードが送信されるという問題に直面しています。これは私のコードです:

<?php
$message = "<table width='100%' border='0' cellspacing='0' cellpadding='3'>
  <tr>
    <td colspan=2>Dear ".$_POST['fname']."&nbsp;".$_POST['lname'].",</td>
  </tr>
   <tr>
    <td colspan=2>Thank you for contacting us.We will get back to you in next 48 hrs.Your Contacts Details are as follows:</td>
  </tr>
  <tr>
    <td width='28%' >Title</td>
    <td width='72%'>".$_POST['title']."</td>
  </tr>
  <tr>
    <td>Email</td>
    <td>".$_POST['email']."</td>
  </tr>
  <tr>
    <td>Your Message</td>
    <td>".$_POST['message']."</td>
  </tr>
  <tr>
    <td>How did you hear about us? </td>
    <td>".$checkBox."</td>
  </tr>
</table>
";  

$subject = "ContactUs";
$headers .= "From: ".$from_mail." \r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

mail($_POST["coach"], $subject, $message, $headers);

?>

そして、私が電子メールで受け取っている出力は次のようになります。

<table width='100%' border='0' cellspacing='0' cellpadding='3'>
  <tr>
    <td colspan=2>Dear Test User,</td>
  </tr>
   <tr>
    <td colspan=2>Thank you for contacting us.Your Contacts Details are as follows:</td>
  </tr>
  <tr>
    <td width='28%' >Title</td>
    <td width='72%'>Mr.</td>
  </tr>
  <tr>
    <td>Email</td>
    <td>test@example.com</td>
  </tr>
  <tr>
    <td>Your Message</td>
    <td>Test Message</td>
  </tr>
  <tr>
    <td>How did you hear about us? </td>
    <td>www.example.com</td>
  </tr>
</table>

なぜこれが起こっているのか分かりません。任意の提案をいただければ幸いです。

4

3 に答える 3

3

これを試して

$header  = "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset: utf8\r\n";

も試してください:PHPMailer

于 2012-12-06T09:56:29.803 に答える
0

ヘッダー部分に次のコードを追加します

<?php
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
?>
于 2012-12-06T11:04:32.180 に答える
0

Use

html_entity_decode()

eg. mail($_POST["coach"], $subject, html_entity_decode($message), $headers);
于 2012-12-06T09:58:12.007 に答える