电子邮件不发送PHP邮件功能[重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

我的页面结构如下

-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 -->

下面是我的send-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.';
}
}

由于某种原因,电子邮件不发送。如果我在联系表单中添加了一个动作=“/ send-form.php”,我可以收到要发送的电子邮件,但这会将我带到另一页。我要做的是让用户发送表单并保持在同一页面上,当被点击时,隐藏的消息将被取消隐藏..任何有关我的电子邮件未发送的帮助将非常感谢!

php html email mailer
1个回答
0
投票

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

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

只需将name =“submit”放在上面就可以解决问题。

<input type="submit" name="submit" value="submit">
© www.soinside.com 2019 - 2024. All rights reserved.