PHP邮件偶尔只发送变量的空白电子邮件

PHP邮件偶尔只发送变量的空白电子邮件,php,email,Php,Email,我有一个在线预订表单,它工作得很好,但我们最近收到了几封预订确认电子邮件,其中包含静态信息,但是php变量没有显示在电子邮件中。系统90%的时间运行良好 代码如下: <?php include 'class.phpmailer.php'; $mid = trim(strip_tags($_POST['mid'])); $bintypeconfirm = trim(strip_tags($_POST['bintypeconfirm'])); $bintype = trim(strip_tag

我有一个在线预订表单,它工作得很好,但我们最近收到了几封预订确认电子邮件,其中包含静态信息,但是php变量没有显示在电子邮件中。系统90%的时间运行良好

代码如下:

<?php
include 'class.phpmailer.php';
$mid = trim(strip_tags($_POST['mid']));
$bintypeconfirm = trim(strip_tags($_POST['bintypeconfirm']));
$bintype = trim(strip_tags($_POST['bintype']));
$amt = trim(strip_tags($_POST['amt']));
$currency = trim(strip_tags($_POST['currency']));
$from = trim(strip_tags($_POST['from']));
$to = trim(strip_tags($_POST['to']));
$pmt_contact_firstname = trim(strip_tags($_POST['pmt_contact_firstname']));
$pmt_contact_surname = trim(strip_tags($_POST['pmt_contact_surname']));
$pmt_contact_phone = trim(strip_tags($_POST['pmt_contact_phone']));
$pmt_sender_email = trim(strip_tags($_POST['pmt_sender_email']));
$regindi_address1 = trim(strip_tags($_POST['regindi_address1']));
$regindi_address2 = trim(strip_tags($_POST['regindi_address2']));
$regindi_sub = trim(strip_tags($_POST['regindi_sub']));
$regindi_state = trim(strip_tags($_POST['regindi_state']));
$regindi_pcode = trim(strip_tags($_POST['regindi_pcode']));
$comments = trim(strip_tags($_POST['comments']));
$agree = trim(strip_tags($_POST['agree']));

$mail = new PHPMailer();       
$body = 'Dear '.$pmt_contact_firstname.', <br><br> We have received your booking and
will be in contact with you as soon as possible to confirm your details.<br>If you have
any further queries you can call us on 1300 826 811.<br>
<table cellpadding="4" width="509">
<tr><th>Skip Bin Details</th></tr>
<tr><td>Bin Size</td><td>'.$bintypeconfirm.'</td></tr>
<tr><td>Bin Type</td><td>'.$bintype.' Waste</td></tr>
<tr><td>Your Price</td><td>$'.$amt.'</td></tr>
<tr><td>Delivery Date</td><td>'.$from.'</td></tr>
<tr><td>Collection Date</td><td>'.$to.'</td></tr>
<tr><td>Additional Comments</td><td>'.$comments.'</td></tr>
<tr><td></td></tr>
<tr><th>Customer Details</th></tr>
<tr><td>First Name</td><td>'.$pmt_contact_firstname.'</td></tr>
<tr><td>Last Name</td><td>'.$pmt_contact_surname.'</td></tr>
<tr><td>Phone</td><td>'.$pmt_contact_phone.'</td></tr>
<tr><td>email</td><td>'.$pmt_sender_email.'</td></tr>
<tr><td>Address Line 1</td><td>'.$regindi_address1.'</td></tr>
<tr><td>Address Line 2</td><td>'.$regindi_address2.'</td></tr>
<tr><td>Suburb</td><td>'.$regindi_sub.'</td></tr>
<tr><td>State</td><td>'.$regindi_state.'</td></tr>
<tr><td>Postcode</td><td>'.$regindi_pcode.'</td></tr>
<tr><td>Agree to Ts & Cs</td><td>'.$agree.'</td></tr>
</table>';

$mail->From       = "enquiries@skiptech.com.au";
$mail->FromName   = "Skiptech";

$mail->Subject    = "Your Online Booking Confirmation | Skiptech Skip Bin Hire";

$mail->AltBody    = "To view the message, please use an HTML compatible email  
viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$mail->AddAddress($_POST[pmt_sender_email]);
$mail->AddCC('enquiries@skiptech.com.au', 'Skiptech');
if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  header("location:https://www.paymate.com/PayMate/ExpressPayment?mid=xxx
amt_editable=N&currency=AUD&ref=not%20required
pmt_sender_email=".$_POST[pmt_sender_email]."
pmt_contact_firstname=".$_POST[pmt_contact_firstname]."
pmt_contact_surname=".$_POST[pmt_contact_surname]."
pmt_contact_phone=".$_POST[pmt_contact_phone]."&pmt_country=Australia
regindi_state=Queensland&regindi_address1=".$_POST[regindi_address1]."
regindi_address2=".$_POST[regindi_address2]."&regindi_sub=".$_POST[regindi_sub]."
regindi_pcode=".$_POST[regindi_pcode]."&return=http://www.skiptech.com.a
/&amt=".$_POST[amt]);
}
?>

此外,这是表格代码,这可能有助于进一步:

echo "<form name='form2' id='form2' action='mailsender.php' method='POST'>
        <input type='hidden' name='mid' id='mid' value='skiptech1'>
        <input type='hidden' name='bintypeconfirm' id='bintypeconfirm'  
value='3 Cubic Metre Skip Bin'>
        <input type='hidden' name='amt' id='amt' value=".$a.">
        <input type='hidden' name='bintype' id='bintype' value=".$table.">
        <input type='hidden' name='currency' id='currency' value='AUD'>
        <table class='quote' align='center' width='97%' border='0'>
        <tr><td colspan='2'><h4>Confirm Your Details</h4></td></tr>
        <tr><td>Requested Delivery Date*</td><td><input type='text'
id='from' name='from' /></td></tr>
        <tr><td>Requested Collection Date* (max 7 days)</td><td><input
type='text' id='to' name='to' /></td></tr>
        <tr><td>First Name*</td><td><input type='text'
id='pmt_contact_firstname' name='pmt_contact_firstname'
class='validate[required,maxSize[30]]'/></td></tr>
        <tr><td>Last Name*</td><td><input type='text'
id='pmt_contact_surname' name='pmt_contact_surname'
class='validate[required,maxSize[30]]'/></td></tr>
        <tr><td>Phone/Mobile Number*</td><td><input type='text'
id='pmt_contact_phone' name='pmt_contact_phone' class='validate[required,
maxSize[15]]'/></td></tr>
        <tr><td>Email*</td><td><input type='text' id='pmt_sender_email'
name='pmt_sender_email' value='' class='validate[required,custom[email,maxSize[50]]'
size='40'/></td></tr>
        <tr><td>Delivery Address line 1*</td><td><input type='text'
id='regindi_address1' name='regindi_address1' size='55' class='validate[required,
maxSize[100]]'/></td></tr>
        <tr><td>Delivery Address line 2</td><td><input type='text'
id='regindi_address2' name='regindi_address2' size='55'
class='validate[maxSize[100]]'/></td></tr>
        <tr><td>Suburb*</td><td><input type='text' id='regindi_sub'
name='regindi_sub' size='40'class='validate[required,maxSize[50]]'/></td></tr>
        <tr><td>State*</td><td><input type='text' id='regindi_state'
value='Queensland' name='regindi_state'
size='40'class='validate[required,maxSize[11]]'/></td></tr>
        <tr><td>Postcode*</td><td><input type='text' id='regindi_pcode'
name='regindi_pcode' value=".urldecode($tags)." class='validate[required,maxSize[4]]'/
</td></tr>
        <tr><td>Additional Requirements e.g. where to place bin.</td
<td><textarea id='comments' name='comments' rows='5' cols='45'
class='validate[maxSize[150]]'></textarea></td></tr>
        <tr><td colspan='2'><div class='flcheck-wrapper'>Checking this box
indicates that you have read and accepted the Cheap Skip Bin Hire Brisbane Terms &
Conditions for Skip Bin Hire:
        <input type='checkbox' id='agree' name='agree'
class='validate[required]'/></div></td></tr>
        <tr><td colspan='2'><div class='pagination'><input type='submit'
id='sender' name='sender' class='quote-button2' value=''/></div></td></tr>
        <tr><td colspan='2'></td></tr>
        </table></form>";
}
echo”
确认您的详细信息
要求的交货日期*
请求的收款日期*(最多7天)
名字*
姓*
电话/手机号码*
电子邮件*
送货地址第1行*
送货地址第2行
郊区*
陈述*

邮政编码*某些网络爬虫将在您的网站上提交表单。这将导致它向您发送一封电子邮件,而输入内容中没有输入任何内容。防止这种情况的解决方案是添加某种字段验证

下面是一个关于如何进行基本Javascript字段验证的链接:

如果您至少输入了一项要求输入的内容,则您将停止接收空白表格提交


(另一方面,一些网络爬虫也会用垃圾邮件填写和提交您的网络表单。在某些情况下,如果失真设置足够低,他们甚至会填写验证码。)

您似乎没有强制执行任何类型的字段已完成的验证,因此可能任何人都可以使用空白字段发布表单(可能是偶然的)抱歉,没有字段的JavaScript验证,除非所有字段都完成了,否则无法提交。而且,空白的电子邮件来自已经预订并填写所有东西的真正客户。表单字段也被提交给支付系统和支付系统。如果正确接收到字段,它们就不会进入电子邮件。@glenn Javascript验证在机器人对您进行爬网时是无用的。它根本不会执行Javascript,因此没有必要进行保护。(但如果电子邮件如你所说来自合法客户,你就必须研究为什么POST值可能是空的。我们无法从你显示的代码中真正分辨出来。)@Pekka웃 我现在已经添加了表单代码,希望这些额外的信息会有所帮助?也许客户禁用了JavaScript,因此通过了空字段的验证?在这种情况下,服务器端验证将帮助Pekka添加服务器端验证的建议+1。可能是爬虫程序或用户禁用了JavaScript。请尝试以下方法类似这样:if($pmt\u sender\u email==“”){//返回表单头}else{//给表单发电子邮件}