【发布时间】:2011-11-06 10:55:53
【问题描述】:
我在一个网站上工作,但在获取 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>
Timberlane Regional High School<br/>
C/O Steven Rugoletti<br/>
36 Greenough Road<br/>
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();
?>
在此先感谢您提供的所有帮助。
【问题讨论】:
-
阅读这篇文章:HOW TO PREVENT YOUR EMAIL TO BE IN SPAM你可以在那篇文章中得到一些提示
-
确保验证您的 $email = $_REQUEST["email"];实际上是一个电子邮件地址。通过在电子邮件地址后添加更多标题,机器人尝试使用您的表单发送垃圾邮件是很常见的。
-
没有地方供用户输入电子邮件...如果它是联系表格,我会担心。但这里是静态值。
-
对表单中的输入字段进行硬编码不会阻止任何人更改它。在您的情况下,您很安全,我检查了 phpmailer 脚本,它会在您添加电子邮件地址时验证它们,因此不可能通过电子邮件输入字段添加其他标题