Javascript HTML表单:通过jQuery和PHP邮件发送额外的通知电子邮件

Javascript HTML表单:通过jQuery和PHP邮件发送额外的通知电子邮件,javascript,php,jquery,html,forms,Javascript,Php,Jquery,Html,Forms,我在一个网站上使用一个表单,它是一个移动公司的CRM软件。这个表单基本上是一个估算请求,它在CRM数据库中写入了一些内容 不幸的是,它不发送电子邮件通知,所以问题是是否可以在不影响其原始用途的情况下将通知功能附加到表单。哪种方法是最优雅的 以下是Granot如何提供的表格(我知道它还可以在许多其他方面进行改进,但这不是我现在的问题): 我试图通过将以下内容直接放在表单所在的页面中触发它(如果有必要,请放在表单上方)。基于@Flynn建议的解决方案,并结合从中复制和粘贴 函数submittery

我在一个网站上使用一个表单,它是一个移动公司的CRM软件。这个表单基本上是一个估算请求,它在CRM数据库中写入了一些内容

不幸的是,它不发送电子邮件通知,所以问题是是否可以在不影响其原始用途的情况下将通知功能附加到表单。哪种方法是最优雅的

以下是Granot如何提供的表格(我知道它还可以在许多其他方面进行改进,但这不是我现在的问题):

我试图通过将以下内容直接放在表单所在的页面中触发它(如果有必要,请放在表单上方)。基于@Flynn建议的解决方案,并结合从中复制和粘贴


函数submittery(){
if(checkData()){
document.theForm.action=”http://gorilla.hellomoving.com/wc.dll?mpdir~moduleret~XXXXX”;
document.theForm.submit();
$.ajax({
类型:“POST”,
url:“/email.php”,
数据:dataString,
});
}
}

控制台不会抛出任何脚本错误。有什么提示我做错了什么吗?谢谢大家!

不幸的是,据我所知,没有办法直接从Javascript发送电子邮件

但是,您可以使用对服务器的AJAX调用来发送电子邮件

function SubmitEntry() {
    if (checkData()) {
        document.theForm.action="http://gorilla.hellomoving.com/wc.dll?mpdir~moduleret~XXXXX";
        document.theForm.submit();
        // Insert AJAX call here
        }
  }

我不知道您使用的是什么Javascript库,但是AJAX调用可以非常简单地使用

如果您使用的是php,当然可以使用许多库,例如phpmailer。我如何将此操作绑定到同一个按钮@Godinall?您可以使用函数提交表单。在表单提交成功时,请致电phpmailer。这听起来非常有帮助@Flynn,但我无法充分连接这些点。是的,该站点正在使用jQuery。我可以用这个发电子邮件吗?你介意再给我一个提示吗?谢谢
<script language="JavaScript" src="http://gorilla.hellomoving.com/XXXXX/formcheck.js"> </script>
<script language="JavaScript" type="text/JavaScript">


function checkData(){
    frm = document.theForm;
    return lengthValid(frm.SNAME, 4,"full name") 
    && emailValid(frm.EMAIL, 4,"Email")
    && lengthValid(frm.STELH, 10,"ten digits phone number")
    && selectValid(frm.MM, "month") 
    && selectValid(frm.DD, "day")   
    && zipValid(frm.SZIP, 5, "five digits origin zip code -US only") 
    && zipValid(frm.RZIP, 5, "five digits destination zip code - US only")
    && selectValid(frm.ROOMS,"weight")
    }

function SubmitEntry() {
        if (checkData()) {
            document.theForm.action="http://gorilla.hellomoving.com/wc.dll?mpdir~moduleret~XXXXX";
            document.theForm.submit();
            }
      }  

function locatezip() {
    window.open('http://gorilla.hellomoving.com/wc.dll?mputil~zipwc~NEW','EANITHING','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no,scrollbars=yes,width=550,height=500');
self.name="main"}
</script>
<?php
if($_POST){
    mail("admin@domain.com", "The form has been filled out", "Head over to Granot and check it out");
}
?> 
<script>

function SubmitEntry() {
    if (checkData()) {
        document.theForm.action="http://gorilla.hellomoving.com/wc.dll?mpdir~moduleret~XXXXX";
        document.theForm.submit();

       $.ajax({
            type: "POST",
            url: "/email.php",
            data: dataString,
        });
        }
  }
</script>
function SubmitEntry() {
    if (checkData()) {
        document.theForm.action="http://gorilla.hellomoving.com/wc.dll?mpdir~moduleret~XXXXX";
        document.theForm.submit();
        // Insert AJAX call here
        }
  }