0

我有一个向网站所有者和表单提交者发送电子邮件的表单。它在任何地方看起来都很棒,但在 iPhone 上它包含所有的 html 代码。

这是我处理表单的代码:

 <?php

 $name_field = $_POST['name'];
 $email_field = $_POST['email'];
 $phone = $_POST['phone'];
 $message = $_POST['message'];
 $link = $_POST['link'];
 $to = 'me@me.com';
 $toCust = $email_field;
 $subject = 'Lead From Website';
 $random_hash = md5(date('r', time()));
 $headers = "From: me@me.com\r\nReply-To: $email; ";
 $headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
 ob_start();
 ?>


 --PHP-alt-<?php echo $random_hash; ?> 
 Content-Type: text/html; charset="UTF-8"
 Content-Transfer-Encoding: 7bit


 <h3>Contact Form Submission From Website</h3>
 <table width="39%" cellpadding="10" border="0">
   <tr>
     <td width="47%"><strong>Name:</strong></td>
     <td width="53%" style='color:#990000'><?php echo $name_field; ?></td>
   </tr>
   <tr>
     <td><strong>Email:</strong></td>
     <td style='color:#990000'><?php echo $email_field; ?></td>
   </tr>
   <tr>
     <td><strong>Phone Number:</strong></td>
     <td style='color:#990000'><?php echo $phone; ?></td>
   </tr>
   <tr>
     <td><strong>Message:</strong></td>
     <td style='color:#990000'><?php echo $message; ?></td>
   </tr>

 </table>

 --PHP-alt-<?php echo $random_hash; ?>--
 <?
 $message = ob_get_clean();
 if(isset($_POST['link']) && $_POST['link'] == ''){


     $mail_sent = @mail( $to, $subject, $message, $headers );
$mail_sent = @mail( $toCust, $subject, $message, $headers );
header('Location: thankyou.html');
 }
 echo $mail_sent ? "Your email has been sent." : "The message failed to send. Our form thinks   you're spam. If you're not, please give us a call";
 ?>

这是我在 iPhone 上以纯文本形式显示的:

--PHP-alt-1962a6e1cb0d62a23c8e1743bd157401 
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: 7bit

<html>
<body>
<h3>Contact Form Submission From Website</h3>
<table width="39%" cellpadding="10" border="0">
  <tr>
    <td width="47%"><strong>Name:</strong></td>
    <td width="53%" style='color:#990000'>Dave</td>
  </tr>
  <tr>
    <td><strong>Email:</strong></td>
    <td style='color:#990000'>me@me.com</td>
  </tr>
  <tr>
    <td><strong>Phone Number:</strong></td>
    <td style='color:#990000'>666-666-6666</td>
  </tr>
  <tr>
    <td><strong>Message:</strong></td>
    <td style='color:#990000'>test of iphone</td>
  </tr>

</table>
</body>
</html>
--PHP-alt-1962a6e1cb0d62a23c8e1743bd157401--
4

1 回答 1

0

您的问题可能在这里:

 Content-Type: text/html; charset="UTF-8"
 Content-Transfer-Encoding: 7bit

UTF-8 和 7 位编码几乎是互斥的,因为 UTF-8 是一种多字节编码。您可能应该切换到quoted-printable 并使用quoted_printable_encode(). 如果您使用的是 PHP < 5.3,则评论中有直接替换。

编辑

$part_header = <<<_EOI_

 --PHP-alt-$random_hash
 Content-Type: text/html; charset="UTF-8"
 Content-Transfer-Encoding: quoted-printable

_EOI_;

$part_body = <<<_EOI_
 <html>
 <body>
 <h3>Contact Form Submission From Website</h3>
 <table width="39%" cellpadding="10" border="0">
   <tr>
     <td width="47%"><strong>Name:</strong></td>
     <td width="53%" style='color:#990000'>$name_field</td>
   </tr>
   <tr>
     <td><strong>Email:</strong></td>
     <td style='color:#990000'>$email_field</td>
   </tr>
   <tr>
     <td><strong>Phone Number:</strong></td>
     <td style='color:#990000'>$phone</td>
   </tr>
   <tr>
     <td><strong>Message:</strong></td>
     <td style='color:#990000'>$message</td>
   </tr>
 </table>
 </body>
 </html>

 --PHP-alt-$random_hash--
 _EOI_;

$message = $part_header . quoted_printable_encode($part_body);
于 2013-02-19T17:14:38.043 回答