Reputation: 11
I'm trying to get my online form to email me the results. The email I receive is: Mail failure - no recipient addresses. I have spent a while trying to fix this and have looked for answers but have not found any. Hoping someone can help me fix this. Thanks!
<?php
$emailSubject = 'Test Form';
$mailTo = '[email protected]';
$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";
?>
<!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>
Upvotes: 1
Views: 1199
Reputation: 1
Is your php file correctly receiving that data? Trying echoing all your variables and see if your variables even contain any data.
If they don't contain anything the problem is most likely the form. Can we see your form?
Upvotes: 0
Reputation: 499
You are using:
$mailTo = '[email protected]';
and next:
$success = mail($mailto,
find the diference $mailTo
Upvotes: 1
Reputation: 54252
In PHP, variables are case sensitive, e.g. $mailTo
is not equal to $mailto
. (However, functions are case insensitive, e.g. MAIL()
is equal to mail()
.)
Thus, the solution is to fix the typo.
Upvotes: 2