Javascript / PHP事件更新注册按钮

时间:2013-07-19 12:26:53

标签: php javascript email

我正在尝试设计一个基本的Javascript电子邮件注册事件更新,就像您在构建和即将发布的页面上看到的那样。访问者将添加他们的电子邮件并单击“提交”以将自己添加到电子邮件列表中,使用基本的Ajax或jQuery“感谢您注册”消息。此外,我还需要使用PHO电子邮件验证器。

HTML

<form action="scripts/mail.php" method="POST">
  <input type="email" name="email" id="email" placeholder="Enter your email here....." tabindex="1">
  <input type="submit" name="submit" id="submitbtn" value="Signup" class="submit-btn" tabindex="2">
</form>

使用下面的PHP文件:

<?php
  $from = "events@spectator.co.uk";
  $email = $_POST['email'];
  $to = "datunrase@pressholdings.com";
  $subject = "Please add me to the events mailing list";
  $mailheader = "Email: $email \r\n";
  mail($to, $subject, $mailheader) or die("Error!");
  echo "<script type=\"text/javascript\">".
    "alert('Thanks! We will keep you updated');".
    "</script>";
?>

然后我使用了这个Javascript SignUp.js:

$(document).ready(function(){
  var mousedownHappened = false;
  $("#submitbtn").mousedown(function() {
    mousedownHappened = true;
  });
  $("#email").focus(function(){
    $(this).animate({
      opacity: 1.0,
      width: '250px'
    }, 300, function(){
      // callback method empty
    });
    // display submit button
    $("#submitbtn").fadeIn(300);
  });
  $("#submitbtn").on("click", function(e){
    e.stopImmediatePropagation();
    $("#signup").fadeOut(230, function(){
      // callback method to display new text
      // setup other codes here to store the e-mail address
      $(this).after('<p id="success">Thanks! We will keep you updated.</p>');
    });
  });
  $("#email").blur(function(){
    if(mousedownHappened) {
      // reset mousedown and cancel fading effect
      mousedownHappened = false;
    } else {
      $("#email").animate({
        opacity: 0.75,
        width: '250px'
      }, 500, function(){
        // callback method empty
      });
      // hide submit button
      $("#submitbtn").fadeOut(400);
    }
  });
});

但我需要帮助才能使其正常运作。首先,我希望电子邮件说明它是谁,但目前没有人说。

此外,我知道当涉及到电子邮件确认文本时,JS和PHP似乎会互相覆盖。所以你能告诉我什么是最好用的吗?在他们注册后,我希望访问者留在同一页面上。感谢。

1 个答案:

答案 0 :(得分:1)

为了正确显示“FROM”,您应该在$ mailheader变量中设置它。改变它:

$mailheader = 'From: ' . $email . "\r\n" .
'Reply-To: '. $email . "\r\n";