doxrxwn2252 2015-12-25 07:35
浏览 38

电子邮件表格不携带电子邮件到PHP脚本

I have an email input field and a submit button, which when pressed I want a text field to change telling the user that they are subscribed. For some reason the email field is not relaying to the php file what email was typed in. However I know the php is being executed because it just give me an subscription error every time. There was another question like this asked on here but the solution did not work.

I think it is an issue with the use of <form> and <button> in combination but I do not know the proper way to execute this, any ideas?

The html:

   <html>
    <head>
      <link rel="stylesheet" href="mystyle.css">
      <title>Community Sound</title>
    </head>   
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $("button").click(function(){
            $.ajax({url: "phEmail.php", success: function(result){
                $("#div1").html(result);
            }});
        });
    });
    </script>  
    <body>
      <!--  Subscription  -->
      <div class="container">
        <div class="no-result vertical-align-outer">
          <div class="vertical-align">
            <form method="post" >
              <input name="email" class="email glowing-border" type="email" placeholder="Enter your email address ...">
              <button type="button" onclick="return getData()" class="emailbtn">Subscribe</button>
            </form>
          </div>
        </div>
      </div>     
         <div id="div1">Not Subscribed</div>
</body>
</head>

PHP:

<?php
$to = "garvernr@mail.uc.edu";
$from = "newsubscription@samplepackgenerator.com";
$headers = "From: " . $from . "
";
$subject = "New subscription";
$body = "New user subscription: " . $_POST['email'];
if( filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) )
{ 
    if (mail($to, $subject, $body, $headers, "-f " . $from))
    {
        echo 'You have been added to our mailing list!';
    }
    else
    {
       echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
    }
}
else
{
   echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';   
}
?>
  • 写回答

2条回答 默认 最新

  • dousha1394 2015-12-25 07:49
    关注

    The problem is that your form doesn't send any data.

    You need to modify your ajax call and add the data arrtibute.

    $("button").click(function(){
       $.ajax({
           url: "phEmail.php",
           data:{email: $("input.email").value},
           success: function(result){
                $("#div1").html(result);
            }
        });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题