我有一个表单,可以向网站所有者和表单提交者发送电子邮件。它看起来很棒,但在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--
答案 0 :(得分:0)
你可能会遇到问题:
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: 7bit
UTF-8和7位编码几乎互相排斥,因为UTF-8是一种多字节编码。您应该切换到quoted-printable并使用quoted_printable_encode()
。如果你正在使用PHP&lt;在评论中有替代品。 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);