我已经到处搜索和研究了,但仍然找不到答案。
我使用的是我们购买的主题(5.2.1版)附带的PHP Mailer。我正试图弄清楚如何捕获电话号码,并将其与发送的电子邮件中的其他数据一起发送。
形式:
<form method="post" action="#" id="contactForm">
<div class="input-prepend" style="margin-left:0px;margin-right:0px">
<input class="input-xlarge required" id="name" type="text" placeholder="Name (Required)" />
</div>
<div class="input-prepend" style="margin-left:0px">
<input class="input-xlarge required" id="email" type="text" placeholder="Email (Required)" />
</div>
<div class="input-prepend" style="margin-left:0px">
<input class="input-xlarge required" id="phone" name="phone" type="text" placeholder="Phone (Required)" />
</div>
<div class="input-prepend" style="margin-left:0px">
<input class="input-xlarge required" id="subject" type="text" placeholder="Subject (Required)" />
</div>
<div class="input-prepend" style="margin-left:0px">
<input class="input-xlarge required" id="children-3-7" type="text" placeholder="Number of Children (Age 3 - 7) (Required)" />
</div>
<div class="input-prepend" style="margin-left:0px">
<input class="input-xlarge required" id="children-7-14" type="text" placeholder="Number of Children (Age 7 - 14) (Required)" />
</div>
<div class="input-prepend" style="margin-left:0px">
<input class="input-xlarge required" id="adults" type="text" placeholder="Number of Adults (Required)" />
</div>
<div class="input-prepend" style="margin-left:0px">
<textarea name="message-input" id="message" class="span12 required" cols="5" rows="5" placeholder="Message (Required)" style="margin-left:0px"></textarea>
</div>
<div class="clearfix" style="margin:10px 0px 0px 0px">
<a href="#" class="ignore btn resetButton"><span>Reset Form</span></a>
<a href="#" class="ignore btn submitButton"><span>Send Message</span></a>
<!-- Processing data trick -->
<div id="loadingForm">
<img src="images/normal/ajax-small.gif" alt="ajax-small" />
</div>
<!-- Processing data trick -->
</div>
<br />
<div class="clearfix">
<!-- contact notice -->
<div class="alert alert-block fade" id="contact-notice">
<span><strong>Warning!</strong> All fields above are required to send the message properly.</span>
</div>
<!-- contact notice -->
</div>
</form>
PHP
<?php
require_once("class.phpmailer.php");
send();
function send(){
$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->Host = 'host.com';
$mailer->SMTPAuth = true;
$mailer->SMTPSecure = "tls";
$mailer->Port = 587;
$mailer->CharSet="utf-8";
$mailer->IsHTML(true);
$mailer->Username = 'mail-bot@mail.com';
$mailer->Password = 'PASSWORD';
$mailer->FromName = $_POST['name'];
$mailer->From = $_POST['email'];
$mailer->AddAddress('ADDRESS','NB=AME');
$mailer->Subject = $_POST['subject'];
$mailer->MsgHTML = $_POST['message'];
$phone = $_POST['phone'];
/**$mailer->Age1 = $_POST['children-3-7'];
//$mailer->Age2 = $_POST['children-7-14'];
//$mailer->Age3 = $_POST['adults'];**/
$mailer->Body = "From : ".$_POST['name']."<br /> E-mail : ".$_POST['email']."<br /> Subject : ".$_POST['subject']."<br />Message : ".$_POST['message']."<br />Phone : $phone";
if(!$mailer->Send()){
echo "error^Message could not be sent.<br />";
echo "Mailer Error: " . $mailer->ErrorInfo;
exit;
}
else{
echo "ok^Message sent successfully!";
}
}
?>
正如你所看到的,我正在尝试使用
$phone = $_POST['phone'];
提取电话号码,然后使用将其添加到消息正文中
$mailer->Body = "From : ".$_POST['name']."<br /> E-mail : ".$_POST['email']."<br /> Subject : ".$_POST['subject']."<br />Message : ".$_POST['message']."<br />Phone : $phone";
注入电话号码
我也尝试过以以下方式注入
$mailer->Body = "From : ".$_POST['name']."<br /> E-mail : ".$_POST['email']."<br /> Subject : ".$_POST['subject']."<br />Message : ".$_POST['message']."<br />Phone: ".$_POST['phone'];
任何帮助都将不胜感激。
在我们的主.js文件中似乎有一个二次验证,它在通过ajax发布空字段之前对空字段进行验证。在它发布之前,需要在那里添加电话号码,我现在可以成功地捕获数据。
谢谢你的帮助!