不使用 PHPmail 函数发送电子邮件

Email not sending with PHPmail function

我的页面结构如下

-index.php
  -include send-form.php
  -include contact-us-form.php
  -include footer.php

我的 index.php 文件如下(已缩短)

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
</head>

<body>

<?php include 'navigation-bar.php';?>
<?php include 'contact-us-form.php';?> 
<?php include 'footer.php';?>

</body>

下面是我的联系方式

<div class="container">
    <div class="row"> 
        <div class="column">
            <form method="post">
                <label for="name">Name*</label>
                <input type="text" id="name" name="name" placeholder="Your name.." required>
                <label for="email">Email*</label>
                <input type="text" id="email" name="email" placeholder="Your email.." required>
                <label for="message">Message*</label>
                <textarea id="message" name="message" placeholder="Your Message" style="height:170px" required></textarea>
                    <div style="text-align: center;">
                        <input type="submit" value="submit" >
                    </div> <!-- /submit button -->
            </form> <!-- /form -->
            <div id="error_message" style="width:100%; height:100%; display:none; ">
                <h4>Error</h4>
                    Sorry there was an error sending your form.
            </div>
            <div id="success_message" style="width:100%; height:100%; display:none; ">
                <h2>Success! Your Message was Sent Successfully.</h2>
            </div>
        </div><!-- /column --> 

        <div class="column2">

      </div> <!-- /column2 -->

  </div> <!-- /row-->
</div> <!-- /container -->

下面是我发的-form.php

if (isset($_POST["submit"])){ 
$to = '***************@gmail.com';
$subject = 'Message from website';
$message = 'MESSAGE: ' . $_POST [ "message" ] . ' </n> NAME:  ' . $_POST['name'] ; 
$from = $_POST[ "email" ];

if(mail($to, $subject, $message)){
    echo 'message sent';
} else{
    echo 'Unable to send email. Please try again.';
}
}

由于某种原因,电子邮件未发送。如果我在联系表单中放置 action="/send-form.php" ,我可以获得要发送的电子邮件,但这会将我带到另一个页面。我想要做的是让用户发送表单并停留在同一页面上,点击后隐藏的消息将被取消隐藏。非常感谢任何关于为什么我的电子邮件未发送的帮助!

我看到您在代码中使用了 $_POST["submit"]。但是您没有在表单上定义它。

<input type="submit" value="submit">

只要加上name="submit",问题就解决了

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