我正在尝试设计一个基本的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在电子邮件确认文本方面似乎会相互覆盖。你能告诉我最好用什么吗?在他们注册后,我希望访问者保持在同一页面上。谢谢
为了正确显示"FROM",您应该在$mailheader变量中设置它。这样改:
$mailheader = 'From: ' . $email . "'r'n" .
'Reply-To: '. $email . "'r'n";