适应邮件功能不起作用

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

First things first:

Change this:

 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.');       

  }

to

 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.');       

  }

You also need look into the function died(). It does not use, $error, the parameter anywhere in the function.

I think You can do emailing by smtp.gmail.com which is mail sever of gmail

<?php

require_once('../classes/class.phpmailer.php');


$mail = new PHPMailer(true); 

$mail->IsSMTP(); 

try {

 // $mail->Host       = "mail.yourdomain.com"; // SMTP server
 // $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)  NOTE:- remove comment to or for test
  $mail->SMTPAuth   = true;                  // enable SMTP authentication
  $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
  $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
  $mail->Port       = 465;                   // set the SMTP port for the GMAIL server
  $mail->Username   = "youremailid@gmail.com";  // GMAIL username
  $mail->Password   = "yourgmailpassword";            // GMAIL passwordAIL password
  $address = "send_to_email_address@gmail.com";
  $mail->AddAddress($address, "friend name");

  //$mail->AddReplyTo("youremail@domain.com","your name");

  $mail->Subject    = "Advanced gmail mailer smtp";


  $mail->MsgHTML(file_get_contents('contents.html'));
  //$mail->AddAttachment('images/1.jpg');      // attachment
  //$mail->AddAttachment('images/2.jpg'); // attachment
  if($mail->Send()){  
        echo "Message Sent OK</p>
";
  }else{
       echo "Sorry some problem  OK</p>
";
  }

} catch (phpmailerException $e) {
        echo $e->errorMessage(); //error messages from PHPMailer
} catch (Exception $e) {
        echo $e->getMessage(); //error messages from anything else!
}
?>

You can use your domain email server or if you dont have then you can try this by gmail smtp server. please note that if you add two-step verification in your gmail account then you should have to remove this two-step verification for sending the email.

You can download my example from this link Here

I Hop It Will Help You!