duanmo5724 2016-12-19 07:49
浏览 384
已采纳

if(isset($ _ post ['submit']))不起作用

I'm learning PHP. A beginner. The code from the tutorial I follow is below.

    <?php
        if (isset($_POST['submit']) && (!empty($_POST['submit']))) {
            $from = 'Alexey Pazukhin (alexey.pazukhin@mail.ru)';
            $subject = $_POST['subject'];
            $text = $_POST['elvismail'];
            $output_form = FALSE;
              if (empty($subject) && empty($text)){
                echo 'Subject and text fields are empty. <br/>';
                $output_form = TRUE;
              }
              if (empty($subject) && (!empty($text))) {
                echo 'Subject field is empty. <br/>';
                $output_form = TRUE;
              }
              if ((!empty($subject)) && empty($text)) {
                echo 'Text field is empty. <br/>';
                $output_form = true;
              }
              if((!empty($subject)) && (!empty($text))){

                 $dbc = mysqli_connect('localhost', 'root', 'root', 'elvis_store') 
        or die ('Connection failed. MySQL');
                 $query = "SELECT * FROM email_list";
                 $result = mysqli_query($dbc, $query) 
        or die('DB query error');
                 while ($row = mysqli_fetch_array($result)) {
                 $first_name = $row['first_name']; 
                 $last_name = $row['last_name'];
                 $msg = "Dear $first_name $last_name, 
 $text";
                 $to = $row['email'];
                 mail($to, $subject, $msg, 'From:' . $from);
                 echo 'Message sent:' . $to . '<br/>';
                 }
               mysqli_close($dbc);
              }
          }
        else {
          $output_form = TRUE;
        }

        if ($output_form) {
        ?>
        <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
        <label for="subject">Subject of email:</label><br />
        <input id="subject" name="subject" type="text" value="<?php echo $subject; ?>" size="30" /><br />
        <label for="elvismail">Body of email:</label><br />
        <textarea id="elvismail" name="elvismail" rows="8" cols="40"><?php echo $text; ?></textarea><br />
        <input type="submit" name="Submit" value="Submit" />
  </form>
<?php
}
?>

The problem is that code doesn't send any mails after clicking Submit button (either I fill the fields or don't) and returns an empty (new) form in browser (Chrome).

  • 写回答

3条回答 默认 最新

  • donglin4636 2016-12-19 07:55
    关注

    Replace

     <input type="submit" name="Submit" value="Submit" />
    

    with

     <input type="submit" name="submit" value="submit" />
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起