我有一个 javascript 函数来操作一些表单数据并将 POST 构建到 php 页面。js 执行 xmlHTTP.open 并发送到构建的 url。
php 页面应该接受参数并发送电子邮件,但它似乎不接受参数。
我知道我在这里遗漏了一些愚蠢的东西,但是我还有其他类似的页面,但是参数更少并且它们工作正常。
<script>
function submitReg()
{
var fn = document.getElementById("textfname").value;
var ln = document.getElementById("textlname").value;
var e = document.getElementById("textemail").value;
var p = document.getElementById("textphone").value;
var pr = document.getElementById("promocode").value;
var c1 = document.getElementById("st-1").innerHTML + "_"
+ document.getElementById("c- 1").innerHTML;
if (document.getElementById("st-2").innerHTML != "")
{
var c2 = document.getElementById("st-2").innerHTML + "_" +
document.getElementById("c-2").innerHTML;
}
if (document.getElementById("st-3").innerHTML != "")
{
var c3 = document.getElementById("st-3").innerHTML + "_" +
document.getElementById("c-3").innerHTML;
}
var myURL = "form-to-email.php?" + "fn=" + fn + "&ln=" + ln + "&e=" + e +
"&p=" + p + "&pr=" + pr + "&c1=" + c1 + "&c2=" + c2 + "&c3=" + c3;
xmlhttp.open("POST", (encodeURI(myURL)), true);
xmlhttp.send();
}
</script>
和 PHP 代码:
<?php
$fname = $_POST["fn"];
$lname = $_POST["ln"];
$email = $_POST["e"];
$phone = $_POST["p"];
$promo = $_POST["pr"];
$county1 = $_POST["c1"];
$county2 = $_POST["c2"];
$county3 = $_POST["c3"];
$email_from = 'support@somesite.com';
$email_subject = "Someone filled out the Splash page";
$email_body = "You have received a new form submission from the user $visitor_email.\n".
"Here it is:\n ".
"First Name: $fname \n".
"Last Name: $lname \n".
"Email: $email \n".
"Phone: $phone \n".
"Promo Code: $promo \n".
"First County: $county1 \n".
"Second County(if Any): $county2 \n".
"Third County(if Any): $county3 \n";
$to = "user@gmail.com";
$headers = "From: $email_from \r\n";
mail($to,$email_subject,$email_body,$headers);
Header("Location: thankyou.html");
?>