我在回来之前做了这个联系表,只是注意到它似乎没有起作用。页面上的一切似乎都很好,但是当我点击提交时,我从未收到电子邮件。有人可以看看它,告诉我你是否看错了。我知道这可能不是制作PHP表单的最佳方式,而是一次一步。
供参考,页面为http://wikimotive.com/contact-us
<div class="myform"><form id="form1" method="POST">
<div class="group"><label>First Name*</label>
<input id="text" class="rounded-corners" type="text" name="first_name" value="<?php echo $_POST['first_name']; ?>"/></div>
<div class="group"><label>Last Name*</label>
<input id="text" class="rounded-corners" type="text" name="last_name" value="<?php echo $_POST['last_name']; ?>"/></div>
<div class="group"><label>Company*</label>
<input id="text" class="rounded-corners" type="text" name="company" value="<?php echo $_POST['company']; ?>"/></div>
<div class="group"><label>Email*</label>
<input id="text" class="rounded-corners" type="text" name="email" value="<?php echo $_POST['email']; ?>"/></div>
<div class="group"><label>Cell Phone</label>
<input id="text" class="rounded-corners" type="text" name="cell_phone" value="<?php echo $_POST['cell_phone']; ?>"/></div>
<div class="group"><label>State*</label>
<select name="state" size="1">
<option value="Alabama">Alabama</option>
<option value="Alaska">Alaska</option>
<option value="Arizona">Arizona</option>
<option value="Arkansas">Arkansas</option>
<option value="California">California</option>
<option value="Canada">Canada</option>
<option value="Colorado">Colorado</option>
<option value="Connecticut">Connecticut</option>
<option value="Delaware">Delaware</option>
<option value="District of Columbia">District of Columbia</option>
<option value="Florida">Florida</option>
<option value="Georgia">Georgia</option>
<option value="Hawaii">Hawaii</option>
<option value="Idaho">Idaho</option>
<option value="Illinois">Illinois</option>
<option value="Indiana">Indiana</option>
<option value="Iowa">Iowa</option>
<option value="Kansas">Kansas</option>
<option value="Kentucky">Kentucky</option>
<option value="Louisiana">Louisiana</option>
<option value="Maine">Maine</option>
<option value="Maryland">Maryland</option>
<option value="Massachusetts">Massachusetts</option>
<option value="Michigan">Michigan</option>
<option value="Minnesota">Minnesota</option>
<option value="Mississippi">Mississippi</option>
<option value="Missouri">Missouri</option>
<option value="Montana">Montana</option>
<option value="Nebraska">Nebraska</option>
<option value="Nevada">Nevada</option>
<option value="New Hampshire">New Hampshire</option>
<option value="New Jersey">New Jersey</option>
<option value="New Mexico">New Mexico</option>
<option value="New York">New York</option>
<option value="North Carolina">North Carolina</option>
<option value="North Dakota">North Dakota</option>
<option value="Ohio">Ohio</option>
<option value="Oklahoma">Oklahoma</option>
<option value="Oregon">Oregon</option>
<option value="Pennsylvania">Pennsylvania</option>
<option value="Rhode Island">Rhode Island</option>
<option value="South Carolina">South Carolina</option>
<option value="South Dakota">South Dakota</option>
<option value="Tennessee">Tennessee</option>
<option value="Texas">Texas</option>
<option value="Utah">Utah</option>
<option value="Vermont">Vermont</option>
<option value="Virginia">Virginia</option>
<option value="Washington">Washington</option>
<option value="West Virginia">West Virginia</option>
<option value="Wisconsin">Wisconsin</option>
<option value="Wyoming">Wyoming</option>
</select>
</div>
<div class="group"><label>Zip Code*</label>
<input id="text" class="rounded-corners" type="text" name="zip_code" value="<?php echo $_POST['zip_code']; ?>"/></div>
<div class="group"><label>Comments</label><textarea class="rounded-corners" name="comments" rows="6" cols="35">
<?php echo $_POST['comments']; ?>
</textarea></div>
<?php function captcha() {
$random = rand(1, 4);
if ($random === 1) {
?><div id="captcha_image"><img src="/wp-content/uploads/2012/04/penny.png" width="170px">
<br />
<span>hint: one word, begins with a "P"</span>
</div>
<div class="group"><label>What's In The Image</label><input id="text" class="rounded-corners" type="text" name="answer" /></div>
<input type="hidden" name="answered" value="1">
<?php }
else if ($random === 2) {
?><div id="captcha_image"><img src="/wp-content/uploads/2012/04/Nickel.jpg" width="170px">
<br />
<span>hint: one word, begins with a "N"</span>
</div>
<div class="group"><label>What's In The Image</label><input id="text" class="rounded-corners" type="text" name="answer" /></div>
<input type="hidden" name="answered" value="2">
<?php }
else if ($random === 3) {
?><div id="captcha_image"><img src="/wp-content/uploads/2012/04/Dime.png" width="170px">
<br />
<span>hint: one word, begins with a "D"</span>
</div>
<div class="group"><label>What's In The Image</label><input id="text" class="rounded-corners" type="text" name="answer" /></div>
<input type="hidden" name="answered" value="3">
<?php }
else {
?><div id="captcha_image"><img src="/wp-content/uploads/2012/04/Quarter.png" width="170px">
<br />
<span>hint: one word, begins with a "Q"</span>
</div>
<div class="group"><label>What's In The Image</label><input id="text" class="rounded-corners" type="text" name="answer" /></div>
<input type="hidden" name="answered" value="4">
<?php }
}
?>
<?php captcha() ?>
<input type="hidden" name="submitted" value="1">
<input name="submit" id="submit" type="submit" value="Submit" />
<?php
if ($_POST['submitted']==1) {
if ($_POST['first_name']) {
$first_name = $_POST['first_name'];
}
else {
$errormsg = "You are missing a required field";
}
if ($_POST['last_name']) {
$last_name = $_POST['last_name'];
}
else {
$errormsg = "You are missing a required field";
}
if ($_POST['company']) {
$company = $_POST['company'];
}
else {
$errormsg = "You are missing a required field";
}
if ($_POST['email']) {
$email = $_POST['email'];
}
else {
$errormsg = "You are missing a required field";
}
if ($_POST['state']) {
$state = $_POST['state'];
}
else {
$errormsg = "You are missing a required field";
}
if ($_POST['zip_code']) {
$zip_code = $_POST['zip_code'];
}
else {
$errormsg = "You are missing a required field";
}
if ($_POST['answer']) {
$answer = $_POST['answer'];
$answer = strtolower($answer);
}
if ($_POST['answered']=== "1" && $answer!="penny") {
$errormsg = "Answer is incorrect";
}
else if ($_POST['answered']=== "2" && $answer!="nickel") {
$errormsg = "Answer is incorrect";
}
else if ($_POST['answered']=== "3" && $answer!="dime") {
$errormsg = "Answer is incorrect";
}
else if ($_POST['answered']=== "4" && $answer!="quarter") {
$errormsg = "Answer is incorrect";
}
if ($errormsg) {
echo "<div class=\"box red\"><p>$errormsg</p></div>";
}
else {
$comments = $_POST['comments'];
$cell_phone = $_POST['cell_phone'];
$formcontent ="From: $first_name $last_name \n Company: $company \n Cell Phone: $cell_phone \n State: $state \n Zip Code: $zip_code \n Comments: $comments";
$recipient = "sales@wikimotive.com";
$subject = "Sales Lead";
$mailheader = "From: $email \r\n";
mail ($recipient, $subject, $formcontent, $mailheader) or die ("Error!");
echo "<div class=\"box green\"><p>Thank You!</p></div>";
}
}
?>
</form></div>
答案 0 :(得分:1)
添加php错误报告,看看你得到了什么错误
直接致电
mail ($recipient, $subject, $formcontent, $mailheader) or die ("Error!");
在一个单独的文件中,检查邮件是否正常工作。