我有一个通过电子邮件发送并发布到数据库的表单。问题是,当它发送到我们自己的服务器(Parallels Plesk)上的电子邮件地址时,它进入Mac Mail它会有点腐败。文本被分解,整个表单上都有$ =。有时它甚至将部分html编码放在电子邮件的顶部,例如:
<= /tr><= td colspan='3'>Further Comments:
= <= /tr><= td width='40%' colspan='2'>Expectations
但每次都略有不同。即每次它发生时都没有它做的事情;每次符号和编码都有一点不同。
这是我发送电子邮件的代码:
<?php
$servername = "***";
$username = "***";
$password = "***";
$dbname = "***";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// prepare sql and bind parameters
$stmt = $conn->prepare("INSERT INTO guestquestionnaire (date_submitted, choice, expectations, res, res_information, res_staff, further_comments1)
VALUES (:date_submitted, :choice, :expectations, :res, :res_information, :res_staff, :further_comments1)");
$stmt->bindParam(':date_submitted', $date, PDO::PARAM_STR);
$stmt->bindParam(':choice', $choice);
$stmt->bindParam(':expectations', $expectations);
$stmt->bindParam(':res', $res);
$stmt->bindParam(':res_information', $res_information);
$stmt->bindParam(':res_staff', $res_staff);
$stmt->bindParam(':further_comments1', $further_comments1);
// insert a row
$date = date('Y-m-d H:i:s');
$choice = $_POST['choice'];
$expectations = $_POST['expectations'];
$res = $_POST['res'];
$res_information = $_POST['res_information'];
$res_staff = $_POST['res_staff'];
$further_comments1 = $_POST['further_comments1'];
$stmt->execute();
}
catch(PDOException $e)
{
echo "Error: " . $e->getMessage();
}
$conn = null;
?>
<?php
require 'PHPMailerAutoload.php';
//PHPMailer Object
$mail = new PHPMailer;
//From email address and name
$mail->From = "info@personalemail.com";
$mail->FromName = "Host Person";
//To address and name
$mail->addAddress("user@icloud.com", "User");
$mail->addAddress("info@personalemail.com"); //Recipient name is optional
//Address to which recipient will reply
$mail->addReplyTo("info@personalemail.com", "Reply");
//CC and BCC
$mail->addCC("cc@example.com");
$mail->addBCC("bcc@example.com");
//Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = "Guest Questionnaire Received";
// Build message.
$img="<img src='http://www.myurl.com/guestquestionnaire/images/star".$_POST['res'].".jpg'>";
$img2="<img src='http://www.myurl.com/guestquestionnaire/images/star".$_POST['res_information'].".jpg'>";
$img3="<img src='http://www.myurl.com/guestquestionnaire/images/star".$_POST['res_staff'].".jpg'>";
$message = '<html><body>';
$message .= "<strong>Guest Questionnaire </strong>";
$message .= "<strong>Received: </strong>";
$message .= "<P>";
$message .= '<table rules="all" style="border: 1px solid #999;" cellpadding="7" width="100%" >';
$message .= "<tr style='background: #566890; font-size: 8pt; font-weight: bold; color: #fff;'><td colspan='3'>Prior to Arrival</td></tr>";
$message .= "<tr style='font-size: 8pt;'><td>What made you choose us for your recent trip? </td><td width='40%' colspan='2'>" . strip_tags($_POST['choice']) . "</td></tr>";
$message .= "<tr style='font-size: 8pt;'><td>Did we meet your expectations as advertised? If no, please state why: </td><td width='40%' colspan='2'>" . strip_tags($_POST['expectations']) . "</td></tr>";
$message .= "<tr style='background: #566890; font-size: 8pt; font-weight: bold; color: #fff;'><td colspan='3'>Making your Reservation</td></tr>";
$message .= "<tr style='font-size: 8pt;'><td>Ease of making your reservation: </td><td width='40%'>$img</td><td width='5%'>" . strip_tags($_POST['res']) . "</td></tr>";
$message .= "<tr style='font-size: 8pt;'><td>Hotel information offered: </td><td width='40%'>$img2</td><td width='5%'>" . strip_tags($_POST['res_information']) . "</td></tr>";
$message .= "<tr style='font-size: 8pt;'><td>Warmth and friendliness of staff: </td><td width='40%'>$img3</td><td width='5%'>" . strip_tags($_POST['res_staff']) . "</td></tr>";
$message .= "<tr style='font-size: 8pt;'><td colspan='3'>Further Comments: </BR></BR>" . strip_tags($_POST['further_comments1']) . "</td></tr>";
$message .= "</table>";
$message .= "<BR>";
$message .= "</table>";
$message .= "</body></html>";
$message .= "</body></html>";
$mail->Body = "".$message."";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="surveystyle.css" media="all" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/jquery.inputfocus-0.9.min.js"></script>
<script type="text/javascript" src="/jquery.main.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.3/jquery-ui.js"></script>
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
</head>
<body>
<div id="container">
<div class="logo-header"><img src="images/logo.jpg" alt="" width="205" height="119" /></div>
我确实经历了很多不同的方法来确定问题出在这个特定表单,我们的服务器和Mac Mail之间。我相信可以在这个表单上更改某些内容以使其正常工作(我只是不知道是什么)。表单在webmail平台上显示正常,其他电子邮件帐户(不在我们的服务器上)显示表单完全正常。
非常感谢任何帮助!!!
更新:
我经历并删除了每一行,看看我是否可以尝试调查错误。似乎问题与表单的长度有关。如果有10个条目左右它会很好(不管字段是什么)但是一旦它超过10个条目它开始给所有奇怪的$ =全部。很奇怪。有什么想法吗?