簡體   English   中英

PHP Mailer-其他字段

[英]PHP Mailer - Additional Fields

我已經搜尋了很多東西,但仍然找不到答案。

我正在使用附帶了我們購買的主題(版本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發布空字段之前對其進行驗證。 在將電話號碼發布之前,需要在其中添加電話號碼,現在我可以成功捕獲數據了。

謝謝你的幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM