发送表单数据-PHP/Javascript/JQuery

发送表单数据-PHP/Javascript/JQuery,javascript,php,jquery,forms,Javascript,Php,Jquery,Forms,我为我确信可能是一个非常简单的问题提前道歉。。。但是我自愿更新了一个非营利组织的网站,我用一个表格进入了这个网站。在过去的两天里,我一直在试图弄明白这一点,但仍然没有取得进展。。。所以我想我应该在这里登记 页面有几个不同的元素,通过切换“隐藏”类来显示/隐藏这些元素 当用户选中“使用礼品援助”时,将显示一个隐藏表单以收集其信息。当他们单击提交时,我希望它显示/隐藏适当的元素,并通过电子邮件将表单内容发送给非营利组织的某个人 显示/隐藏功能工作正常。然而,我似乎不知道如何获得表格来向非营利组织发送

我为我确信可能是一个非常简单的问题提前道歉。。。但是我自愿更新了一个非营利组织的网站,我用一个表格进入了这个网站。在过去的两天里,我一直在试图弄明白这一点,但仍然没有取得进展。。。所以我想我应该在这里登记

页面有几个不同的元素,通过切换“隐藏”类来显示/隐藏这些元素

当用户选中“使用礼品援助”时,将显示一个隐藏表单以收集其信息。当他们单击提交时,我希望它显示/隐藏适当的元素,并通过电子邮件将表单内容发送给非营利组织的某个人

显示/隐藏功能工作正常。然而,我似乎不知道如何获得表格来向非营利组织发送电子邮件

我的表格代码是:

<div id="myDIV" class="hidden" title="Gift Aid Form"><form id="giftAidForm" action="http://www.tinfinitydesign.com/demo/charolette/wp-content/uploads/php/donateform.php" method="post" name="giftAidForm">I want to gift aid my donation of £. <input id="Amount" name="theAmount" size="10" type="text" /> to <u>CHARLOTTE'S BAG (reg# 1169419) </u>.

I am a UK taxpayer and understand that if I pay less Income Tax and/or Capital Gains Tax in the current tax year than the amount of Gift Aid claimed on all my donations it is my responsibility to pay any difference.

<strong>MY DETAILS</strong>

Title: <input id="Title" name="theTitle" size="6" type="text" /> First name or initial(s): <input id="Forename" maxlength="30" name="theForename" size="30" type="text" /> Surname:  <input id="Surname" name="theSurname" size="30" type="text" />

Full Home Address:
<input id="Address1" name="theAddress1" size="100%" type="text" /><input id="Address2" name="theAddress2" size="100%" type="text" /><input id="Address3" name="theAddress3" size="100%" type="text" />
Postcode: <input id="Postcode" name="thePostcode" size="50%" type="text" />
Date:         <input id="theDate" name="theDate" size="50%" type="text" />
<strong>Please notify the charity if you: </strong>
<ul>
    <li>want to cancel this declaration</li>
    <li>change your name or home address</li>
    <li>no longer pay sufficient tax on your income and/or capital gains</li>
</ul>
If you pay Income Tax at the higher or additional rate and want to receive the additional tax relief due to you, you must include all your Gift Aid donations on your Self-Assessment tax return or ask HM Revenue and Customs to adjust your tax code.

<hr />

<table border="0" width="100%" cellspacing="0" cellpadding="0" align="right">
<tbody>
<tr>
<td align="left">
<blockquote><a id="btnCancel" href="#"><strong>CANCEL</strong></a></blockquote>
</td>
<td align="right">
<blockquote><a id="btnSubmit" href="#"><strong>SUBMIT</strong></a></blockquote>
</td>
</tr>
他们当前的站点基本上使用了一个模式,然后在提交时重定向到一个新的捐赠页面。但是,我为WordPress使用的主题不允许情态动词

他们提供的php代码是:

// SETUP THE EMAIL ADDRESS TO SEND TO, THE SUBJECT and FROM (can be anything)
$to = 'info@charlottesbag.com' ;
$subject = 'Gift Aid Form Completed' ;
$from = 'info@charlottesbag.com';

// SETS UP THE BODY OF THE EMAIL AND INSERTS THE FILLED IN DETAILS
$message = "I want to Gift Aid my Donation of £" . $_POST [ "theAmount" ] . " to:\n";
$message.= "Name of Charity: CHARLOTTE'S BAG (reg num 1169419)\n\n";
$message.= "I am a UK taxpayer and understand that if I pay less Income Tax and/or Capital Gains Tax in the current tax year than the amount of Gift Aid claimed on all my donations it is my responsibility to pay any difference.\n\n";
$message.= "My Details\n\n";
$message.= "Title: " . $_POST [ "theTitle" ] ."      " ;
$message.= "First name / inital(s): " . $_POST [ "theForename" ] ."\n";
$message.= "Surname: " . $_POST [ "theSurname" ] ."\n";
$message.= "Full Home Address: " . $_POST [ "theAddress1" ] ."\n";
$message.=  "                  " . $_POST [ "theAddress2" ] ."\n";
$message.=  "                  " . $_POST [ "theAddress3" ] ."\n";
$message.=  "Postcode: " . $_POST [ "thePostcode" ] ."    ";
$message.=  "Date: " . $_POST [ "theDate" ] ."\n";


$headers = 'From: ' . $from . PHP_EOL ;

//SENDS THE EMAIL TO CRESSY
mail ( $to, $subject, $message, $headers ) ;

// THE TEXT IN QUOTES BELOW IS WHAT WILL BE
// DISPLAYED TO USERS AFTER SUBMITTING THE FORM. REDIRECTS TO THE NEXT DONATION PAGE FOR PAYMENT
echo "<script>window.location.href='http://www.tinfinitydesign.com/demo/charolette/donate-with-gift-aid/'</script>";
//设置要发送到的电子邮件地址、主题和发件人(可以是任何内容)
$to$info@charlottesbag.com' ;
$subject='已完成的礼品援助表';
$frominfo@charlottesbag.com';
//设置电子邮件正文并插入已填写的详细信息
$message=“我想捐赠我的%$_POST[“theAmount”]。“收件人:\n”;
$message.=“慈善机构名称:夏洛特的包(注册号1169419)\n\n”;
$message.=“我是英国纳税人,我明白如果我在当前纳税年度缴纳的所得税和/或资本利得税少于我所有捐赠的礼品援助金额,我有责任支付任何差额。\n\n”;
$message.=“我的详细信息\n\n”;
$message.=“标题:”$_张贴[“标题”];
$message.=“名字/起始名称:”$_张贴[“theForename”]。“\n”;
$message.=“姓氏:”$_发布[“theSurname”]。“\n”;
$message.=“完整家庭地址:”$_发布[“theAddress1”]。“\n”;
$message.=''$_张贴[“theAddress2”]。“\n”;
$message.=''$_张贴[“theAddress3”]。“\n”;
$message.=“邮政编码:”$_POST[“邮政编码”]。“”;
$message.=“日期:”$_张贴[“日期”]。“\n”;
$headers='From:'$从…起PHP_EOL;
//将电子邮件发送给CRESSY
邮件($to、$subject、$message、$headers);
//下面引号中的文字将是
//提交表单后显示给用户。重定向到下一个捐款页面进行付款
echo“window.location.href=”http://www.tinfinitydesign.com/demo/charolette/donate-with-gift-aid/'";

如有任何见解,将不胜感激。谢谢大家!

这是一种非常简单的清理方法,它将使用过滤器去除所有HTML标记,然后对电子邮件标题注入进行有限的检查。这不是防弹的,但总比没有好

我没有测试过这个代码

在处理代码时,可以使用
var\u dump
查看变量的内容

而不是这个

echo "<script>window.location.href='http://www.tinfinitydesign.com/demo/charolette/donate-with-gift-aid/'</script>";
header('Location: http://www.tinfinitydesign.com/demo/charolette/donate-with-gift-aid/'); exit;
echo
方法向客户端发送JavaScript,必须使用
header
来解释和执行JavaScript,从而减轻浏览器读取内容的负担,并告诉它获取不同的页面。
如果这太冗长,请道歉。

这可能是电子邮件问题,而不是PHP问题。发送电子邮件的代码是否与电子邮件的目的地位于同一服务器上?它位于同一服务器上。然而,最初的PHP在提交到我试图避免的新页面时使用重定向。服务器可能被配置为拒绝来自自身的电子邮件。这是共享主机吗?试着编写一个电子邮件功能,只发送一封电子邮件给你,以找出参数。一旦你成功了,请更新你的代码。直接在电子邮件中嵌入$\u帖子,而不进行任何消毒或验证是非常危险的,而且表单会被垃圾邮件发送者滥用。这是直接嵌入$\u帖子吗?如果这是一个明显的问题,我很抱歉——我完全不明白这一点。
// Removes items from inputs which 
// could be used by spammers to send emails from your server
// Ref: http://nyphp.org/PHundamentals/8_Preventing-Email-Header-Injection
function safe( $name ) {
   return( str_ireplace(array( "\r", "\n", "%0a", "%0d", "Content-Type:", "bcc:","to:","cc:" ), "", $name ) );
}
echo "<script>window.location.href='http://www.tinfinitydesign.com/demo/charolette/donate-with-gift-aid/'</script>";
header('Location: http://www.tinfinitydesign.com/demo/charolette/donate-with-gift-aid/'); exit;