【发布时间】:2014-01-01 00:03:24
【问题描述】:
我一直在尝试多种方法将电子邮件地址输入到此处的表单中:http://contest.realfamilytrips.com 保存到某种文件中。我没有运气。现在我正在尝试通过电子邮件向自己发送每个条目,但也没有太多运气。
我整理了一些 PHP 代码(经过数小时的研究。我对这方面的事情还很陌生)应该在每次用户在表单中输入他们的电子邮件地址时向我发送电子邮件,但事实并非如此不工作。
这是一个单页着陆页,因此没有大量代码。我想分享 index.html 和我的 php 脚本,以及样式表和 functions.js 文件。如果有人能告诉我如何保存或通过电子邮件发送这些电子邮件地址,我将不胜感激。
索引.html:
<!DOCTYPE html>
<html lang="en-US" xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<title>iPad Air Giveaway</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="css/images/favicon.ico" />
<link rel="stylesheet" href="css/style.css" type="text/css" media="all" />
<link rel="stylesheet" href="css/video-js.css" type="text/css" media="all" />
<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="js/html5.js" type="text/javascript"></script>
<script src="js/functions.js" type="text/javascript"></script>
<link rel="shortcut icon" href="favicon.ico" >
<link rel="icon" type="image/gif" href="animated_favicon1.gif" >
</head>
<body class="type-3">
<p></p>
<!-- Shell -->
<div class="shell"><!-- Sidebar --> <aside id="sidebar">
<div class="item"><img src="css/images/ipadgraphic.png" alt="win an ipad air" /></div>
<p style="text-align: left;">Enter sweepstakes to win a brand new iPad Air. Unsubscribe<br /> anytime. <a href="http://realfamilytrips.com/real-family-trips-great-family-itinerary-contest-terms-conditions/">Click here for official terms and conditions</a></p>
</aside> <!-- END Sidebar --> <!-- Content --><section id="content"><!-- Logo -->
<h1 id="logo"><a href="http://realfamilytrips.com" title="home">Real Family Trips</a></h1>
<div>
<h2>Win an iPad Air</h2>
<h2 class="pull-up">For The Best Family Itinerary</h2>
<p style="text-align: left;" class="intro-text"><em>Hey there World Traveler!</em></p>
<p style="text-align: left;" class="intro-text"><em>Want to win an <span class="largetext">iPad Air</span> in a contest for the best family itinerary? Start by answering the question below. You can also share this with others, so more families can learn how to travel with their kids for the best experience!<span size="-1"><a href="http://realfamilytrips.com/real-family-trips-great-family-itinerary-contest-helpful-hints/" style="text-decoration: none; border-bottom: 1px solid #095DF7;"> more details</a></span></em></p>
<!-- Step 1 -->
<div class="steps step-1">
<h2 style="font-size: 26px;">STEP 1: Answer this question</h2>
<form action="#" method="post">
<div class="select-holder"><label>Who is giving away a new 7.5" retina display iPad Air?</label>
<div class="select-wrap"><select name=""> <option selected="selected" value="Select Your Answer">Select Your Answer</option> <option value="LeadBrite, Duh!">RealFamilyTrips, hello...</option> <option value="Lady Gaga">My next door neighbor</option> <option value="Santa Claus">Santa Claus</option> </select></div>
</div>
<input value="Submit Answer " class="submit-button" type="submit" /></form>
<div class="contest-ends">
<p><span>Contest Ends</span></p>
<p>January 31st, 2014 2:00 pm E.S.T.</p>
</div>
</div>
<!-- END Step 1 -->
<!-- Step 2 -->
<div class="steps step-2">
<h2 style="font-size: 26px;">STEP 2: Your details</h2>
<form action="signup.php" method="post" name="emailaddy">
<input type="text" class="field" value="Enter your email address" title="Enter your email address" />
<input type="submit" value="Send" class="send" />
</form>
<div class="contest-ends">
<p><span>Contest Ends</span></p>
<p>January 31st, 2014 2:00 pm E.S.T.</p>
</div>
</div>
<!-- END Step 2 -->
<!-- Step 3 -->
<div class="steps step-3">
<h2 style="font-size: 26px;">STEP 3: Submit Itinerary</h2>
<a href="http://realfamilytrips.com/share-itineraries"> <input value="Go!" class="send" type="submit" /> </a>
<div class="contest-ends">
<p><span>Contest Ends</span></p>
<p>January 31st, 2014 2:00 pm E.S.T.</p>
</div>
</div>
<!-- END Step 3 -->
<p class="inspired">brought to you by <a href="http://realfamilytrips.com">Real Family Trips</a></p>
</div>
</section><!-- END Content -->
<div class="cl"> </div>
</div>
<!-- END Shell -->
<p></p>
</body>
</html>
SIGNUP.php:
<?php
/* Subject and Email variables */
$emailSubject = 'Real Family Trips Contest';
$webmaster = lifeleavesscars@gmail.com
/* Gathering Data Variables */
$emailField = $_POST['emailaddy'];
$body = <<<EOD
<br><hr><br>
Email address: $email <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail ($webmaster, $emailSubject, $body, $headers);
?>
样式.css:
@import url('fonts.css');
* { margin: 0; padding: 0; outline: 0; }
body, html { height: 100%; }
body {
font-size: 18px;
line-height: 24px;
font-family: 'SegoeUI', arial, sans-serif;
color: #314b7b;
background: #fff url(images/body1.png) repeat-y center 0;
min-width: 980px;
}
a { color: #0252aa; text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
a img { border: 0; }
em { font-style: normal; font-family: 'SegoeUI-Italic'; }
.largetext { font-size:150%; font-weight:bold; }
input, textarea, select { font-size: 18px; font-family: 'SegoeUI', arial, sans-serif; }
textarea { overflow: auto; }
select { background:none repeat scroll 0 0 transparent; border: 0; font-family: 'SegoeUI'; font-size: 14px; line-height: 24px; width: 367px; -webkit-appearance: menulist; margin: 0 5px 0 4px; }
.cl { display: block; height: 0; font-size: 0; line-height: 0; text-indent: -4000px; clear: both; }
.notext { font-size: 0; line-height: 0; text-indent: -4000px; }
.left, .alignleft { float: left; display: inline; }
.right, .alignright { float: right; display: inline; }
h2 { font-family: 'SegoeUI-Bold'; font-size: 30px; line-height: 36px; color: #314b7b; text-align:center; font-weight: normal; }
h2 span { font-size: 36px; display: block; padding-bottom: 2px; }
.shell { width: 960px; margin: 0 auto; }
#logo { width: 289px; margin: 0 auto; font-size: 0; line-height: 0; padding-bottom: 14px; }
#logo a { display: block; width: 289px; height: 62px; background: url(images/logo.png) no-repeat 0 0; text-indent: -4000px; }
#sidebar { display: inline; float: left; width: 503px; padding-top: 32px; }
#sidebar h2 { width: 380px; margin: 0 auto; margin-top: 30px; }
#content { display: inline; float: right; padding: 27px 13px 0 11px; width: 415px; }
#content h2 { color: #010101; text-shadow: 0 1px #fff; padding-right: 6px; letter-spacing: -1px; }
#content h2.pull-up { position: relative; margin-top: -6px; padding-bottom: 17px; }
#content p.intro-text { width: 372px; margin: 0 auto; text-align:center; padding: 0 0 9px 24px; }
#content p.inspired { font-size: 15px; text-align:center; color: #8f8f8f; text-shadow: 1px 2px 1px #f6f6f6 }
#content p.inspired a { color: #8f8f8f; text-decoration: underline; }
#content p.inspired a:hover { text-decoration: none; }
.steps { padding-bottom: 29px; }
.steps p { font-size: 20px; line-height: 30px; color: #010101; width: auto; text-align:center; }
.steps form label { display: block; padding-bottom: 23px; }
.steps form p a { color: #015978; text-decoration: underline; }
.steps form p a:hover { text-decoration: none; }
.steps form .select-holder { margin-top: 7px; padding: 13px 19px 20px 13px; background: #fff; }
.steps .select-wrap { width: 375px; border: solid 1px #707070; padding: 2px 0 4px 0; margin-left: 1px; }
.steps .submit-button { display: block; width: 346px; height: 73px; margin: 16px auto 0; background: url(images/submit-button.png) no-repeat 0 0; border: 0; }
.steps .submit-button { font-family: 'SegoeUI-Bold'; font-size: 30px; color: #212121; cursor: pointer; text-shadow: 0 1px #faf562; letter-spacing: -1px; }
.steps .submit-button:hover { background-position: 0 -73px; }
.steps .send { display: block; width: 346px; height: 73px; margin: 16px auto 0; background: url(images/send.png) no-repeat 0 0; border: 0;}
.steps .send { font-family: 'SegoeUI-Bold'; font-size: 30px; color: #212121; cursor: pointer; text-shadow: 0 1px #faf562; letter-spacing: -1px; }
.steps .send:hover { background-position: 0 -73px; }
.steps .field { margin: 25px 0 17px 6px; padding: 10px 20px 11px; line-height: 28px; width: 366px; box-shadow: inset 3px 5px 3px 3px #f5f5f5; background: #fff; border: solid 1px #d7d7d7; }
.step-2 { display: none; }
.step-3 { display: none; }
.contest-ends { padding-top: 16px; }
.contest-ends p { font-size: 20px; line-height: 24px; color: #8f8f8f; text-shadow: 0 1px #fff; text-align:center; }
.contest-ends p span { display: block; line-height: 18px; font-size: 15px; }
body.type-2 { background: #e1e1e1 url(images/body2.png) repeat-x 0 0; }
body.type-2 #wrapper { background: url(images/wrapper.jpg) no-repeat center 0; }
body.type-2 #logo { width: 365px; }
body.type-2 #logo a { width: 365px; height: 62px; background: url(images/logo2.png) no-repeat 0 0; }
body.type-2 .steps p { color: #fff; }
body.type-2 #sidebar h2 { margin-top: 10px; width: auto; color: #2e0035; }
body.type-2 #content p.intro-text { font-family: 'MuseoSlab-500'; font-size: 24px; line-height: 30px; width: auto; padding: 2px 0 16px 0; color: #2e0035; }
body.type-2 .select-holder { margin-left: 2px; }
body.type-2 .select-holder label { padding-bottom: 13px; }
body.type-2 .submit-button { margin-top: 23px; }
body.type-3 { background: #fff url(images/body3.png) repeat-y center 0; }
body.type-3 .shell { width: 874px; }
body.type-3 #logo { padding-bottom: 19px; }
body.type-3 #sidebar { padding-top: 29px; width: 354px; }
body.type-3 #sidebar h2 { padding: 0 0 42px 0; margin-top: 9px; width: 280px; }
body.type-3 #content { width: 495px; }
body.type-3 #content h2.pull-up { padding-bottom: 22px; }
body.type-3 #content p.intro-text { padding: 0 0 27px 10px; width: 433px; }
body.type-3 .steps p { letter-spacing: 1px; }
body.type-3 .select-holder { margin: 16px 30px 0 35px; padding: 13px 19px 20px 18px; }
body.type-3 .submit-button { margin-top: 29px; }
body.type-3 .contest-ends { padding-top: 12px; }
body.type-3 .field { margin: 20px 0 17px 47px; }
body.type-3 #sidebar p { font-size: 12px; line-height: 18px; color: #666666; text-align:center; padding-right: 14px; padding-left: 14px; }
body.type-3 #sidebar p a { color: #666; text-decoration: underline; }
body.type-3 #sidebar p a:hover { text-decoration: none; }
#mc_embed_signup{ font:14px Helvetica,Arial,sans-serif; text-align: center; }
FUNCTIONS.js
$(function () {
$(document).on('focusin', '.field, textarea', function () {
if (this.title == this.value) {
this.value = '';
}
}).on('focusout', '.field, textarea', function () {
if (this.value === '') {
this.value = this.title;
}
});
$(document).on('click', '.submit-button', function () {
if ($('select').find('option:selected').index() === 0) {
alert('Select Your Answer.');
return false;
}
if ($('select').find('option:selected').index() !== 1) {
alert('Your guess is wrong! Please try again.');
return false;
} else {
$('.step-1').hide();
$('.step-2').fadeIn(800);
return false;
}
});
$(document).on('submit', 'form', function (e) {
// Check email address
// if email address ok
$('.step-2').hide();
$('.step-3').fadeIn(800);
e.preventDefault();
// else
// alert
// e.preventDefault();
// end if
});
});
感谢并为所有代码感到抱歉。我不知道是否需要它,但经过这么多天的尝试,我认为 jquery 可能与 php 混淆了?没有把握。目前我不知道。
提前致谢。
【问题讨论】:
-
每个文件的开头和结尾都有引号吗?
-
一方面,您的 signup.php 代码在
$webmaster = lifeleavesscars@gmail.com中缺少分号,因此仅此一项就会引发错误并破坏您的代码。修复它并再次测试它。编辑:作为Barmar mentioned。将该行更改为$webmaster = "lifeleavesscars@gmail.com"; -
电子邮件地址周围也缺少引号。
-
在第 1 步中,为什么你有一个哪儿也不去的表格?
-
您在第一个表单上缺少结束表单标记,我认为 div 不匹配。使用良好的代码缩进来帮助发现这些类型的错误。您是否打开了错误报告?您是否尝试过 HTML 格式化程序?