Php Ajax POST不工作$\u POST

Php Ajax POST不工作$\u POST,php,jquery,html,ajax,Php,Jquery,Html,Ajax,我正试图通过ajax向php文件提交一个联系人表单。我使用phpMailer发送表单结果。然而,该职位似乎没有发挥作用。提交时,不会执行成功或错误条件。当我注释掉POST变量时,ajax请求成功执行,电子邮件发送(变量为空)。这是代码 <form method="post" class="form2" id="form2Id" name="form" action=""> <div class="formtitle">Form<<

我正试图通过ajax向php文件提交一个联系人表单。我使用phpMailer发送表单结果。然而,该职位似乎没有发挥作用。提交时,不会执行成功或错误条件。当我注释掉POST变量时,ajax请求成功执行,电子邮件发送(变量为空)。这是代码

<form  method="post" class="form2" id="form2Id" name="form" action="">

            <div class="formtitle">Form<</div>

            <div class="input">
                <div class="inputtext">Your Name: </div>
                <div class="inputcontent">

                    <input id="nameId" type="text" name="name" />

                </div>
            </div>

            <div class="input">
                <div class="inputtext">Your Phone Number: </div>
                <div class="inputcontent">

                    <input id="phoneNumberId" type="text" name="phoneNumber" />

                </div>
            </div>

            <div class="input">
                <div class="inputtext">Your Email Address: </div>
                <div class="inputcontent">

                    <input id="emailAddressId" type="text" name="emailAddress"/>

                </div>
            </div>

            <div class="inputtextbox nobottomborder">
                <!--<div class="inputtext">Message: </div>-->
                <div class="inputcontent">

                    <!--<textarea id="messageId" class="textarea" name="message"></textarea>-->

                </div>
            </div>

            <div class="buttons">

                <input class="orangebutton" type="submit" id="formSubmit" value="Submit" />

            </div>

        </form>
<?php

require("./PHPMailer-master/class.phpmailer.php");
include("./PHPMailer-master/class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

//collect the posted variables into local variables before calling $mail = new mailer

$nameId = $_POST['nameId'];
$phoneNumberId = $_POST['phoneNumberId'];
$emailAddressId = $_POST['emailAddressId'];

$mail = new PHPMailer();

//$body = file_get_contents('contents.html');
//$body = eregi_replace("[]",'',$body);

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "lll"; // SMTP server
//$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "lll@gmail.com"; // GMAIL username
$mail->Password = "..."; // GMAIL password

$mail->SetFrom('lll@gmail.com', 'UUU');

$mail->AddReplyTo("lll@gmail.com","UUU");

$mail->Subject = "Email subject";
optional, comment out and test
$mail->MsgHTML($body);


$address = $emailAddressId;
$mail->AddAddress($address, "MMM");



$mail->Body="
 Name: $nameId
 Phone: $phoneNumberId
 Email: $emailAddressId
";

if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "
 <h2>Thank you. We will contact you shortly.</h2>
 ";
}
 ?>
$nameId = $_POST['name'];
$phoneNumberId = $_POST['phoneNumber'];
$emailAddressId = $_POST['emailAddress'];

<form  method="post" class="form2" id="form2Id" name="form" action="">

            <div class="formtitle">Form<</div>

            <div class="input">
                <div class="inputtext">Your Name: </div>
                <div class="inputcontent">

                    <input id="nameId" type="text" name="name" />

                </div>
            </div>

            <div class="input">
                <div class="inputtext">Your Phone Number: </div>
                <div class="inputcontent">

                    <input id="phoneNumberId" type="text" name="phoneNumber" />

                </div>
            </div>

            <div class="input">
                <div class="inputtext">Your Email Address: </div>
                <div class="inputcontent">

                    <input id="emailAddressId" type="text" name="emailAddress"/>

                </div>
            </div>

            <div class="inputtextbox nobottomborder">
                <!--<div class="inputtext">Message: </div>-->
                <div class="inputcontent">

                    <!--<textarea id="messageId" class="textarea" name="message"></textarea>-->

                </div>
            </div>

            <div class="buttons">

                <input class="orangebutton" type="submit" id="formSubmit" value="Submit" />

            </div>

        </form>
<?php

require("./PHPMailer-master/class.phpmailer.php");
include("./PHPMailer-master/class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

//collect the posted variables into local variables before calling $mail = new mailer

$nameId = $_POST['nameId'];
$phoneNumberId = $_POST['phoneNumberId'];
$emailAddressId = $_POST['emailAddressId'];

$mail = new PHPMailer();

//$body = file_get_contents('contents.html');
//$body = eregi_replace("[]",'',$body);

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "lll"; // SMTP server
//$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "lll@gmail.com"; // GMAIL username
$mail->Password = "..."; // GMAIL password

$mail->SetFrom('lll@gmail.com', 'UUU');

$mail->AddReplyTo("lll@gmail.com","UUU");

$mail->Subject = "Email subject";
optional, comment out and test
$mail->MsgHTML($body);


$address = $emailAddressId;
$mail->AddAddress($address, "MMM");



$mail->Body="
 Name: $nameId
 Phone: $phoneNumberId
 Email: $emailAddressId
";

if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "
 <h2>Thank you. We will contact you shortly.</h2>
 ";
}
 ?>
$nameId = $_POST['name'];
$phoneNumberId = $_POST['phoneNumber'];
$emailAddressId = $_POST['emailAddress'];


任何帮助都将不胜感激。

给定html行
和此php代码
$nameId=$\u POST['nameId'
您最终将得到一个空的
$nameId
,因为发布的值位于
$\u POST['name']
中。其他变量也是如此。

如果我注释掉post变量

<form  method="post" class="form2" id="form2Id" name="form" action="">

            <div class="formtitle">Form<</div>

            <div class="input">
                <div class="inputtext">Your Name: </div>
                <div class="inputcontent">

                    <input id="nameId" type="text" name="name" />

                </div>
            </div>

            <div class="input">
                <div class="inputtext">Your Phone Number: </div>
                <div class="inputcontent">

                    <input id="phoneNumberId" type="text" name="phoneNumber" />

                </div>
            </div>

            <div class="input">
                <div class="inputtext">Your Email Address: </div>
                <div class="inputcontent">

                    <input id="emailAddressId" type="text" name="emailAddress"/>

                </div>
            </div>

            <div class="inputtextbox nobottomborder">
                <!--<div class="inputtext">Message: </div>-->
                <div class="inputcontent">

                    <!--<textarea id="messageId" class="textarea" name="message"></textarea>-->

                </div>
            </div>

            <div class="buttons">

                <input class="orangebutton" type="submit" id="formSubmit" value="Submit" />

            </div>

        </form>
<?php

require("./PHPMailer-master/class.phpmailer.php");
include("./PHPMailer-master/class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

//collect the posted variables into local variables before calling $mail = new mailer

$nameId = $_POST['nameId'];
$phoneNumberId = $_POST['phoneNumberId'];
$emailAddressId = $_POST['emailAddressId'];

$mail = new PHPMailer();

//$body = file_get_contents('contents.html');
//$body = eregi_replace("[]",'',$body);

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "lll"; // SMTP server
//$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "lll@gmail.com"; // GMAIL username
$mail->Password = "..."; // GMAIL password

$mail->SetFrom('lll@gmail.com', 'UUU');

$mail->AddReplyTo("lll@gmail.com","UUU");

$mail->Subject = "Email subject";
optional, comment out and test
$mail->MsgHTML($body);


$address = $emailAddressId;
$mail->AddAddress($address, "MMM");



$mail->Body="
 Name: $nameId
 Phone: $phoneNumberId
 Email: $emailAddressId
";

if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "
 <h2>Thank you. We will contact you shortly.</h2>
 ";
}
 ?>
$nameId = $_POST['name'];
$phoneNumberId = $_POST['phoneNumber'];
$emailAddressId = $_POST['emailAddress'];


只要我输入有效的电子邮件地址,电子邮件就会成功发送。否则,电子邮件根本不会发送。在这两种情况下,ajax都会返回成功的响应。我已经尝试了上面的建议,使用名称而不是ID,但它不起作用。

尝试打印($\u POST);在php中,查看变量get postin to page是什么,然后从中解析您的需求值,就像在ajax数据选项中使用Serialize数据一样,在连接到表单、通过ajax提交表单、在php中处理表单、发送响应并通过电子邮件发送其内容的过程中,出现了什么问题?请缩小你的问题范围。将其精简为一段最小的代码来重现问题。如果我对post VAR进行注释,请尽量缩小您的问题范围,