PHP邮件表单没有从html获取字段

时间:2011-08-30 01:19:23

标签: php ajax forms email smtp

我正在网站上工作,我在收到PHP邮件脚本以将表单内容发送到电子邮件时遇到问题。这是为了俱乐部的学生注册。您可以查看当前表单的链接是http://trhs-snowriders.com/register.htm,我将非常感谢任何有邮件编程经验并确保交付的人的帮助。 我拥有服务器,所以我可以做任何必要的调整
邮件正在发送,但通常在垃圾邮件文件夹中。我遇到的另一个问题是php脚本没有从html表单中获取值...这是html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN"> 

<html> 
<head> 
<title>Timberlane Snowriders Registration</title> 


<META http-equiv="last-modified" content="Module 3-1, 2010-12-16"/> 

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"/> 
<!--Begin Custom JavaScript Form Validator--> 
<script type="text/javascript"> 
function valbutton(thisform)
{
var l=document.forms["registrationForm"]["lastName"].value;
var f=document.forms["registrationForm"]["firstName"].value;
if (l==null || l=="")
{
alert("Last Name must be filled out!");
return false;
}
if (f==null || f=="")
{
alert("First Name must be filled out!");
return false;
}
if (document.registrationForm.level.selectedIndex==0)
{
alert("Please select your Skiing/Boarding ability!");
document.registrationForm.level.focus();
return false;
}
myOption = -1;
for (i=thisform.emergency.length-1; i > -1; i--) {
if (thisform.emergency[i].checked) {
myOption = i; i = -1;
}
}
if (myOption == -1) {
alert("You must select Yes or No");
return false;
}
myOption2 = -1;
for (i=thisform.consent.length-1; i > -1; i--) {
if (thisform.consent[i].checked) {
myOption2 = i; i = -1;
}
}
if (myOption2 == -1) {
alert("You must select Yes or No");
return false;
}
myOption3 = -1;
for (i=thisform.procedure.length-1; i > -1; i--) {
if (thisform.procedure[i].checked) {
myOption3 = i; i = -1;
}
}
if (myOption3 == -1) {
alert("You must select Yes or No");
return false;
}
thisform.submit();
}
</script> 
<!--End custom JavaScript Form Validator--> 
<SCRIPT LANGUAGE="JavaScript"> 

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin

image1 = new Image();
image1.src=images/return_dark.gif;

image3 = new Image();
image3.src=images/prices_dark.gif;

image4 = new Image();
image4.src=images/members_dark.gif;

image5 = new Image();
image5.src=images/gallery_dark.gif;

image6 = new Image();
image6.src=images/fitness_dark.gif;

image7 = new Image();
image7.src=images/contact_dark.gif;

image8 = new Image();
image8.src=images/calendar_dark.gif;

image9 = new Image();
image9.src =images/emergency_dark.gif;

// End -->
</script> 

</head> 

<body background="images/silver-diamond-plate.jpg" link="black" vlink="blue" alink="red"     marginheight="0" marginwidth="0" topmargin="0" bottommargin="0"> 
<table border="0" cellspacing="0" cellpadding="0"> 
<tr><td width="1280" height="768"> 
<table align="center" width="1280" height="768" border="0" cellpadding="1"     cellspacing="2" align="left"> 
<tr> 
<td rowspan="10" width="250" height="760" align="center" valign="top"     background="images/pats_sidebar.jpg" title="Night view of Pat's Peak"> 

<a href="index.htm" onmouseover="image1.src='images/return_dark.gif';"     onmouseout="image1.src='images/return.gif';"> 
<img name="image1" src="images/return.gif" border="0"/ title="Return to Snowriders"></a> 

<a href="register.htm" onmouseover="image2.src='images/registration_dark.gif';"     onmouseout="image2.src='images/registration.gif';"> 
<img name="image2" src="images/registration.gif" border="0"/ title="Registration"></a> 

<a href="prices.htm" onmouseover="image3.src='images/prices_dark.gif';" onmouseout="image3.src='images/prices.gif';"> 
<img name="image3" src="images/prices.gif" border="0"/ title="2010 Prices"></a> 

<a href="members.htm" onmouseover="image4.src='images/members_dark.gif';" onmouseout="image4.src='images/members.gif';"> 
<img name="image4" src="images/members.gif" border="0"/ title="Members"></a> 

<a href="gallery.htm" onmouseover="image5.src='images/gallery_dark.gif';" onmouseout="image5.src='images/gallery.gif';"> 
<img name="image5" src="images/gallery.gif" border="0"/ title="Photo Gallery"></a> 

<a href="fitness.htm" onmouseover="image6.src='images/fitness_dark.gif';" onmouseout="image6.src='images/fitness.gif';"> 
<img name="image6" src="images/fitness.gif" border="0"/ title="Getting in Shape"></a> 

<a href="contact.htm" onmouseover="image7.src='images/contact_dark.gif';" onmouseout="image7.src='images/contact.gif';"> 
<img name="image7" src="images/contact.gif" border="0"/ title="Contact Us"></a> 

<a href="calendar.htm" onmouseover="image8.src='images/calendar_dark.gif';"     onmouseout="image8.src='images/calendar.gif';"> 
<img name="image8" src="images/calendar.gif" border="0"/ title="Contact Us"></a> 

<a href="faq.htm" onmouseover="image9.src='images/question_dark.gif';"     onmouseout="image9.src='images/question.gif';"> 
<img name="image9" src="images/question.gif" border="0"/ title="Frequently Asked      Questions"></a> 

<a href="emergency.htm" onmouseover="image10.src='images/emergency_dark.gif';"  onmouseout="image10.src='images/emergency.gif';"> 
<img name="image10" src="images/emergency.gif" border="0"/ title="Emergency"></a> 

</tr></td> 
<tr> 
<td colspan="2" width="1030" height=226 rowspan="1" colspan="1" align="center"    valign="top">  
<img src="images/registration.jpg" title="Snowriders main banner"</td> 
<tr> 

<td bgcolor=silver colspan="2" width="1030" height="100" align="center" valign="middle"> 
<font face="arial" color=red size="6"><b>Status:</b></font></p> 
<font face="arial" color=navy size="5"><b>We are currently registering members for 2011-    2012.<br/>Check the <a href="members.htm">members listing</a> here:</b></p></font> 
</td> 
</tr> 

<td background="images/opacity1.JPG" colspan="2" width="1030" height="300" rowspan="1"     colspan="1" align="left" valign="top"><font face="Comic Sans MS" size=7 color=black></p>   <center>Registration is first-come, first-served.<br/>Complete the following SIX steps:    </center></p></font> 

<font face="Comic Sans MS" size=6 color=black> 

<blockquote><ol type="decimal" start="1"> 
<li>Print and fill out the <a href="forms/contact_form.pdf" target="_blank">"Emergency     Contact Form."</a></li> 
<li>Read the <a href="forms/warning_consent.pdf" target="_blank">"Warning and Consent Agreement."</a></li> 
<li>Read the <a href="forms/prices_procedures.pdf" target="_blank">"Prices and Procedures sheet."</a></li> 
<li>Fill in and submit the following form:<br/> 
(This form will generate an e-mail, that will automatically be sent)</p></li> 
</ol></blockquote> 
</font></td> 
 </tr> 
<td colspan="2" width="100%" rowspan="1" align="center" valign="top"> 

<form name="registrationForm" action="form2email.php" method="post" enctype="text/plain"> 
<input type="hidden" name="email" value="formsender@trhs-snowriders.com" /> 
<input type="hidden" name="redirect" value="http://trhs-       snowriders.com/registercomplete.html#regcom" /> 
<center> 
<table border="2" cellpadding="3" cellspacing="2" bgcolor="gray"> 
<tr> 
   <td align="right"><font face="Comic Sans MS" size="4"><b>Student's Last Name:</b></font>         <input type="text" name="lastName" align="left" size="50"/></td> 
</tr> 
<tr> 
    <td align="right"><font face="Comic Sans MS" size="4"><b>Student's First Name:</b>       <font> <input type="text" name="firstName" align="left" size="50"/></td> 
</tr> 
<tr> 
<td align="right"><font face="Comic Sans MS" size="4"><b>Mother's Last Name (if different)</b></font> <input type="text" name="mother" align="left" size="50"/></td> 
</tr> 
<tr> 
<td align="right"><font face="Comic Sans MS" size="4"><b>Father's Last Name (if different)</b></font> <input type="text" name="father" align="left" size="50"/></td> 
</tr> 
<tr> 
<td align="right"><font face="Comic Sans MS" size="4"><b>What is your skiing/boarding   ability?</b></font> 
<select name="level"> 
<option selected> (please choose)</option> 
<option>I've never skied/boarded before</option> 
<option>I've had a few lessons and I can stop and turn</option> 
<option>I can ski/board on easy slopes</option> 
<option>I can ski/board on more challenging slopes</option> 
<option>I can do it all!!</option> 
</select> 
</tr> 
<tr> 
<td align="right" ><font face="Comic Sans MS" size="4"><b>I have filled in, printed, and     signed the "Emergency Contact" form.</b></font> 
<input type="radio" name="emergency" value="Yes" /> Yes
<input type="radio" name="emergency" value="No" />No 
</tr> 
<tr> 
<td align="right" ><font face="Comic Sans MS" size="4"><b>I have read and understand the   "Warning and Consent Agreement."</b></font> 
<input type="radio" name="consent" value="Yes" /> Yes
<input type="radio" name="consent" value="No" />No 
</tr> 
<tr> 
<td align="right" ><font face="Comic Sans MS" size="4"><b>I have read and understand the   "Prices and Procedures Sheet."</b></font> 
<input type="radio" name="procedure" value="Yes" /> Yes
<input type="radio" name="procedure" value="No" />No 
</tr> 
<tr> 
<td col span="2" align="center"><font face="Comic Sans MS" size="4"> 
<b>Is there something I need to know that isn't included in this form?</b></font> 
<br> 
<textarea name="extrastuff" rows="5" cols="60"></textarea></td></tr> 
<tr><td colspan="2"> 
<center><input type="SUBMIT" value="Submit" onclick="valbutton(registrationForm);return false;" /></center> 
</td></tr> 
</table></form> 
</td> 
</tr> 

<td background="images/opacity1.JPG" colspan="2" width="1030" height="300" rowspan="1"    colspan="1" align="left" valign="top"><font face="Comic Sans MS" size=6 color=black></p>Once    you have submitted the form online, please do the following:</p> 
<blockquote><ol type="decimal" start="5"> 
<li>Write a check for $50 to <i><b>"Timberlane" or "TRHS"</b></i></p> 
This check is <u>NON-REFUNDABLE</u> unless the bus is filled and we can replace your      seat with someone from the waiting list.</p></li> 
<li>Have your student bring the printed "Emergency Contact Form" and the signed check to     Mr. Rugoletti in Room 114 or place it in his mailbox in the front office.</p> 
Forms and checks may also be mailed to:
<blockquote><blockquote><blockquote><blockquote><blockquote> 
&nbsp;Timberlane Regional High School<br/> 
&nbsp;C/O Steven Rugoletti<br/> 
&nbsp;36 Greenough Road<br/> 
&nbsp;Plaistow, NH  03865
</blockquote> 
</ol> 
<font face="Comic Sans MS" size="4" color=navy>Snowriders is a Timberlane Regional High     School sponsored activity.  The National Ski Patrol <a     href="http://www.nsp.org/slopesaftey/respcode.aspx" target="_blank">"Resonsibility Code,"    </a> in addition to school rules and polices, available in the Timberlane <a     href="http://www.timberlanehs.com/handbook.pdf" target="_blank">student handbook</a>, will     be in effect at all times.  Failure to abide by these policies may result in loss of time on     the slopes, removal of one's lift ticket, suspension from the group, and possibly removal     from the group.
</font></td> 
</tr> 
</table> 
<font face="Times New Roman" size="4" color=black><b> 
<SCRIPT 
LANGUAGE="JavaScript"> 
<!-- Javascripts resource by Hypergurl!! 
http://www.hypergurl.com --> 
<!-- hide script begin 
var m = "Page updated  " + document.lastModified; 
var p = m.length-8; document.writeln("<center>"); 
document.write(m.substring(p, 0)); 
document.writeln("</center>"); 
// End --> </SCRIPT> 
</b></font> 
</td></tr></table> 
</body> 
</html>

这是processReg.php文件

<?php
//change settings here
$your_email = "formsender@trhs-snowriders.com";
$your_smtp = "mail.trhs-snowriders.com";
$your_smtp_user = "formsender+trhs-snowriders.com";
$your_smtp_pass = "passwordhere";
$your_website = "http://trhs-snowriders.com";


require("phpmailer/class.phpmailer.php");


//get contact form details
$name = $_REQUEST["name"];
$email = $_REQUEST["email"];
$url = 'registercomplete.html#regcom';

//start phpmailer code 

$ip = $_SERVER["REMOTE_ADDR"];
$user_agent = $_SERVER['HTTP_USER_AGENT'];

$response = "Date: " . date("d F, Y h:i:s A",time()+ 16 * 3600 - 600);
$response .= "IP Address: " . $ip;
$response .= "User-agent:" . $user_agent;
$response .= "----------------------";
$response .= "\n\n";
$response .= "Last Name: " . $_REQUEST["lastName"] . "\n";
$response .= "First Name: " . $_REQUEST["firstName"] . "\n";
$response .= "Mothers Last Name: " . $_REQUEST["mother"] . "\n";
$response .= "Fathers Last Name: " . $_REQUEST["father"] . "\n";
$response .= "Riding Ability: " . $_REQUEST["level"] . "\n";
$response .= "Emergency: " . $_REQUEST["emergency"] . "\n";
$response .= "Consent: " . $_REQUEST["consent"] . "\n";
$response .= "Procedure: " . $_REQUEST["procedure"] . "\n";
$response .= "Extra Stuff: \n";
$response .= $_REQUEST["extrastuff"];

$mail = new PHPmailer();
$mail->SetLanguage("en", "phpmailer/language");
$mail->From = $your_email;
$mail->FromName = $your_website;
$mail->Host = $your_smtp;
$mail->Mailer   = "smtp";
$mail->Password = $your_smtp_pass;
$mail->Username = $your_smtp_user;
$mail->Subject = "New Snowriders Registration";
$mail->SMTPAuth  =  "true";

$mail->Body = $response;
$mail->AddAddress($your_email,"$your_website");
$mail->AddReplyTo($email,$name);


if (!$mail->Send()) {
echo "<p>There was an error in sending mail, please try again at a later time</p>";
echo "<p>".$mail->ErrorInfo."</p>";
} else {
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
}

$mail->ClearAddresses();
$mail->ClearAttachments();

?>

提前感谢所有可以提供的帮助。

3 个答案:

答案 0 :(得分:1)

您的邮件脚本不是问题,除非它根本不发送它。你应该检查的是它发送它的IP地址。有很多已被列入黑名单的IP地址。因此,他们将您的电子邮件视为垃圾邮件。

点击此处 - &gt; http://network-tools.com/default.asp?prog=sbl

或此处 - &gt; http://whatismyipaddress.com/blacklist-check

答案 1 :(得分:1)

如上所述,更改您使用电子邮件发送的标头。您可能需要将其设置为您的网站。默认情况下,它可能是随机的,如

s12290318823-host112390823@host.com

这肯定会将您的邮件发送到垃圾邮件文件夹

答案 2 :(得分:1)

您无法在脚本中执行任何操作来解决此问题。在这个时代,您需要一个正确配置的邮件服务器。这需要正确实现(至少)以下内容:

  • 邮件服务器的正确反向DNS条目
  • SPF
  • Domainkeys&amp; DKIM

还要确保邮件服务器禁用开放中继,未列入任何DNSBL并且不托管任何“垃圾邮件”列表。一旦您的邮件服务器配置正确,主要的电子邮件提供商需要几天(几周?)才能意识到您不是一个邪恶的垃圾邮件发送者。

OTOH,如果您手中没有邮件服务器配置,请转到包含所有这些内容的设置。