我的页面结构如下
-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.';
}
}
由于某些原因,电子邮件未发送。如果在联系表单中放置一个action =“ / send-form.php”,我可以收到要发送的电子邮件,但这将我带到了另一个页面。我要做的是让用户发送表单并留下在同一页面上,单击该按钮后隐藏的消息将不被隐藏。非常感谢您对为什么我的电子邮件不发送的任何帮助!
答案 0 :(得分:0)
我看到您在代码中使用了$ _POST [“ submit”]。但是您没有在表单上定义它。
<input type="submit" value="submit">
只需将name =“ submit”放在上面,就必须解决该问题。
<input type="submit" name="submit" value="submit">