我有一个工作正常的在线预订表格,但我们最近收到了一些预订确认电子邮件,其中静态信息通过,但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¤cy=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®indi_address1=".$_POST[regindi_address1]."
regindi_address2=".$_POST[regindi_address2]."®indi_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>";
}
答案 0 :(得分:0)
某些网页抓取工具会在您的网站上提交表单。这将导致它向您发送一封没有输入任何内容的电子邮件。防止这种情况的解决方案是添加某种字段验证。
以下是有关如何进行基本Javascript字段验证的链接: http://www.w3schools.com/JS/js_form_validation.asp
如果您至少输入一个要求输入的内容,那么您将停止接收空白表单提交。
(另外,一些网页抓取工具也会填写并提交带有垃圾邮件的网页表单。在某些情况下,如果失真设置足够低,他们甚至会填写验证码。)