My problem is very frustrating and im pulling out my hair. Ive taken an exmaple of the php mail function and attempted to adapt it to suit my needs. The example works with an html form that posts to a php file. The example can be found at this link http://www.freecontactform.com/email_form.php
I have taken this exact code and attempted to change nothing but the names of inputs and the number of them.
This example works perfectly when testing on my domain online, ive sent it to my gmail a number of times and in quick succession just to check it wasnt getting filtered for spam.
My simplified adapted version is as follows.
HTML form
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<form name="results" method="post" action="mailresultstest.php">
<table>
<tr>
<td>email<input type"text" name="email" size="20"></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>HOME TEAM</td>
<td><input type="text" name="hometeam" size="20" maxlength="25"></td>
<td>VS</td>
<td>AWAY TEAM</td>
<td><input type="text" name="awayteam" size="20" maxlength="25"></td>
</tr>
<tr>
<td>Round 1</td>
<td><input type="text" name="playerhome1" size="20"></td>
<td><input type="text" name="playeraway1" size="20"></td>
<td>
</td>
</tr>
<tr>
<td><input type="submit" value="submit"> </td>
</table>
</form>
</body>
</head>
</html>
And the php mailresultstest.php
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "mygmailaccount@gmail.com";
$email_subject = "Match Results";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error_message."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['hometeam']) ||
!isset($_POST['awayteam']) ||
!isset($_POST['email']) ||
!isset($_POST['playerhome1']) ||
!isset($_POST['playeraway1']) || {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$hometeam = $_POST['hometeam']; //
$email_from = $_POST['email']; // required
$awayteam = $_POST['awayteam']; //
$playerhome1 = $_POST['playerhome1']; //
$playeraway1 = $_POST['playeraway1']; //
$error_message = "";
if(strlen($hometeam) < 2) {
$error_message .= 'The hometeam you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.
";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Home team: ".clean_string($hometeam)."
";
$email_message .= "Away team: ".clean_string($awayteam)."
";
$email_message .= "Round 1 Home player: ".clean_string($playerhome1)."
";
$email_message .= "Round 2 Away player: ".clean_string($playeraway1)."
";
// create email headers
$headers = 'From: '.$email_from."
".
'Reply-To: '.$email_from."
" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
My adapted code was originally much much more complex and had a number more input fields including selects than what im posting here but not matter what i do to simplify it when i submit the form the php returns nothing and the email is not sent.
In my original adaptation i didnt use of the any string length check or $error_message and my original form didnt have an email field i just added it back in to satisfy the intial if statement and the header. Ive tried removing this field and its existing from the php code and using
if(isset ($_POST['submit']
but alas to no avail. Im honestly just at a loss for why it works perfectly for the example and not at all for my version. I really can not see any difference barr the names of the variables.
ANY help would be appreciated. Thanks in advance