与PHP无效的HTML文件中的联系表格



以下是我的HTML页面contact表格

<form action="" method="POST" enctype="multipart/form-data">
  <input type="hidden" name="action" value="submit">
  <div class="field name-box">
    <input type="text" name="first_name" placeholder="Who Are You?" />
    <label for="first_name">First Name</label>
    <span class="ss-icon">check</span>
  </div>
  <div class="field name-box">
    <input type="text" name="last_name" placeholder="What is your Last Name?" />
    <label for="last_name">Last Name</label>
    <span class="ss-icon">check</span>
  </div>
  <div class="field email-box">
    <input type="text" name="email" placeholder="example@email.com" />
    <label for="email">Email</label>
    <span class="ss-icon">check</span>
  </div>
  <div class="field phonenum-box">
    <input type="text" name="telephone" placeholder="Phone Number" />
    <label for="telephone">Phone</label>
    <span class="ss-icon">check</span>
  </div>
  <div class="field msg-box">
    <textarea name="comment" rows="4" placeholder="Your message goes here..." /></textarea>
    <label for="comment">Message</label>
    <span class="ss-icon">check</span>
  </div>
  <div class="send wow shake" data-wow-duration="1s" data-wow-delay=".3s">
    <input type="submit" value="Send email">
  </div>
</form>

这是我的PHP部分

在html中的接触表格

    <?php
$action=$_REQUEST['action'];
if ($action=="")    /* display the contact form */
    {
    ?>

接触表格

              <?php
    } 
else                /* send the submitted data */
    {
    $first_name=$_REQUEST['first_name'];
    $last_name=$_REQUEST['last_name'];
    $email=$_REQUEST['email'];
    $telephone=$_REQUEST['telephone'];
    $comment=$_REQUEST['comment'];
    if (($first_name=="")||($last_name=="")||($email=="")||($telephone=="")||($comment==""))
        {
        echo "All fields are required, please fill <a href="">the form</a> again.";
        }
    else{       
        $from="From: $first_name<$email>rnReturn-path: $email";
        $subject="Message sent using your contact form";
        // mail("divyansh025@gmail.com", $subject, $comment, $from);
        echo "Thank You For Contacting Us.";
        }
    }  
?>

注意我在同一index.php中使用两个代码我收到谢谢你的消息,但没有收到。同一服务器上的其他站点正在工作。

更改

 $action=$_REQUEST['action'];
 if ($action=="") 

to

if($_SERVER['REQUEST_METHOD'] == 'POST')

我以您的形式看到的其他问题:

  1. $ _请求方法易于安全漏洞使用$ _post。
  2. 您尚未对从用户收到的输入进行任何消毒检查。请这样做。
  3. 正如我从您的表格中看到的那样,您要发送邮件。那为什么您已经评论了发送邮件的邮件?

因此,要使邮件函数在php.ini set中添加/更改

[mail function]
; For Win32 only.
SMTP = smtp.secureserver.net //ADDRESS OF YOUR SMTP SERVER

希望它对您有帮助。

最新更新