【问题标题】:PHP mail form not getting fields from htmlPHP邮件表单没有从html获取字段
【发布时间】: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> 
&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();

?>

在此先感谢您提供的所有帮助。

【问题讨论】:

  • 阅读这篇文章:HOW TO PREVENT YOUR EMAIL TO BE IN SPAM你可以在那篇文章中得到一些提示
  • 确保验证您的 $email = $_REQUEST["email"];实际上是一个电子邮件地址。通过在电子邮件地址后添加更多标题,机器人尝试使用您的表单发送垃圾邮件是很常见的。
  • 没有地方供用户输入电子邮件...如果它是联系表格,我会担心。但这里是静态值。
  • 对表单中的输入字段进行硬编码不会阻止任何人更改它。在您的情况下,您很安全,我检查了 phpmailer 脚本,它会在您添加电子邮件地址时验证它们,因此不可能通过电子邮件输入字段添加其他标题

标签: php ajax forms email smtp


【解决方案1】:

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

  • 邮件服务器的正确反向 DNS 条目
  • 防晒系数
  • 域键和 DKIM

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

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

【讨论】:

  • 所有这些都是很好的建议。我发现我从反向 dns 获得了最多的成功,然后是 spf。我从来没有亲自设置过 dkim。
  • 是的,我认为 Yahoo、Hotmail 等开始接受域密钥签名的电子邮件。据我所知,没有人坚持使用 DKIM。
【解决方案2】:

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

在这里查看-> http://network-tools.com/default.asp?prog=sbl

或这里-> http://whatismyipaddress.com/blacklist-check

【讨论】:

  • 我也遇到了邮件脚本没有从 html 表单中获取值的问题,而是发送了一封只有 php 中设置的值的空白电子邮件......而且 ip 似乎没有被列入黑名单。
  • 嗯,根据你告诉我的,我不能给你答案。发布您的代码。让我们看看发生了什么。
【解决方案3】:

如上所述,更改随电子邮件发送的标题。您可能必须将其设置为您的网站。默认情况下,它可能是随机的,例如

s12290318823-host112390823@host.com

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

【讨论】:

  • 你永远不应该使用“如上所述”这个词。答案的顺序发生了变化。你应该说就像“M. of CA”给出的答案一样......
猜你喜欢
  • 2014-11-14
  • 1970-01-01
  • 2023-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多