douqiao5552 2014-04-12 20:01
浏览 36

适应邮件功能不起作用

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

  • 写回答

2条回答 默认 最新

  • dongqing5575 2014-04-12 20:16
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c