php表单错误 - 邮件失败 - 没有收件人地址

时间:2015-01-09 09:31:00

标签: php email

我试图让我的在线表单通过电子邮件向我发送结果。我收到的电子邮件是:邮件失败 - 没有收件人地址。我花了一段时间试图解决这个问题,并寻找答案,但没有找到任何答案。希望有人可以帮我解决这个问题。谢谢!

<?php

$emailSubject = 'Test Form';
$mailTo = 'nobody@example.com';

$nameField = $_POST['name'];
$emailField = $_POST['email'];
$questionField = $_POST['ships'];
$enemyField = $_POST['enemy'];
$roundsField = $_POST['rounds'];
$winnerField = $_POST['winner'];
$movementsField = $_POST['movements'];
$notesField = $_POST['notes'];

$body = <<<EOD
<br><hr><br>
Name: $nameField <br>
Email: $emailField <br>
Friendly Ships Played: $shipsField <br>
Enemy Ships Played: $enemyField <br>
# of Rounds Played: $roundsField <br>
Who Won?: $winnerField <br>
Movements in Question: $movementsField <br>
Notes: $notesField <br>
EOD;

$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($mailto, $emailSubject, $body, $headers);

$theResults = <<<EOD
Thank You for your help!
EOD;

echo "$theResults";
?>

&#13;
&#13;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Form</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="form_mailer.php">
<table width="455" border="0" cellspacing="1" cellpadding="0" style="margin: 0 auto;">
  <tr>
    <td width="175" height="44" align="left"><label for"name">Name</label></td>
  </tr>
  <tr>
    <td width="280"><input name="name" type="text" id="name" size="30" value="Your Name" onfocus="if (this.value=='Your Name') this.value='';"/></td>
  </tr>
  <tr>
    <td height="45" align="left"><label for="email">Email</label></td>
  </tr>
  <tr>
    <td><input name="email" type="text" id="email" size="30" value="Your Email" onfocus="if (this.value=='Your Email') this.value='';"/></td>
  </tr>
  <tr>
    <td height="45" align="left"><label for="ships">Friendly Ships Played</label></td>
  </tr>
  <tr>
    <td><input name="ships" type="text" id="ships" size="30" value="Enterprise D " onfocus="if (this.value=='Enterprise D ') this.value='';"/></td>
  </tr>
  <tr>
    <td height="45" align="left"><label for="enemy">Enemy Ships Played</label></td>
  </tr>
  <tr>
    <td><input name="enemy" type="text" id="enemy" size="30" value="Borg Sphere " onfocus="if (this.value=='Borg Sphere ') this.value='';"/></td>
  </tr>
  <tr>
    <td height="45" align="left"><label for="rounds"># of Rounds Played</label></td>
  </tr>
  <tr>
    <td><input name="rounds" type="text" id="rounds" size="30" value="6 " onfocus="if (this.value=='6 ') this.value='';"/></td>
  </tr>
  <tr>
    <td height="45" align="left"><label for="winner">Who Won?</label></td>
  </tr>
  <tr>
    <td><input name="winner" type="text" id="winner" size="30" value="Enterprise D " onfocus="if (this.value=='Enterprise D ') this.value='';"/></td>
  </tr>
  <tr>
    <td height="45" align="left"><label for="movements"><br>Movements in Question<br>(Closing=C, Retreating=R, Distance=D)</label></td>
  </tr>
  <tr>
    <td><br><input name="movements" type="text" id="movements" size="30" value="C, D3, 3Right / R, D2, 5Forward " onfocus="if (this.value=='C, D3, 3Right / R, D2, 5Forward ') this.value='';"/></td>
  </tr>
  <tr>
    <td height="41" align="left"><label for="notes">Notes</label></td>
  </tr>
  <tr>
    <td><textarea name="notes" cols="30" rows="5" id="notes" onfocus="if (this.value=='Put any notes in here.') this.value='';">Put any notes in here.</textarea></td>
  </tr>
  <tr>
    <td height="38" align="left">
    <label>
      <input type="submit" name="Submit" id="Submit" value="Submit" />
	  <input type="reset" value="Reset">
    </label></td>
  </tr>
</table>

</form>
</body>
</html>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:2)

在PHP中,变量区分大小写,例如$mailTo不等于$mailto。 (但是,函数不区分大小写,例如MAIL()等于mail()。)

因此,解决方案是解决错误。

答案 1 :(得分:1)

您正在使用:

$mailTo = 'nobody@example.com';

和下一个:

$success = mail($mailto,

找到差异$ male T o

答案 2 :(得分:0)

你的php文件是否正确接收了这些数据?尝试回显所有变量,看看你的变量是否包含任何数据。

如果他们不包含任何内容,则问题很可能就是表单。我们能看到你的表格吗?