我有一个向网站所有者和表单提交者发送电子邮件的表单。它在任何地方看起来都很棒,但在 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--