【发布时间】:2015-11-20 08:38:40
【问题描述】:
所以我有一个表格:
<form method="post" action="contactus.php?message=ok" name="myForm" autocomplete="off">
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name" maxlength="60" required/>
<label for="email">Email:</label>
<input type="text" name="email" id="email" maxlength="120" required/>
<label for="message">Message:</label><br />
<textarea name="message" rows="20" cols="20" id="message" required></textarea>
<input type="submit" name="submit" value="Submit" class="submit-button" onsubmit="displayMessage()" />
以及发送电子邮件的代码:
<?php
if($_POST["submit"]) {
// The message
$message=$_POST["message"];
$email=$_POST["email"];
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");
// Send
mail('myemail.co.uk', $email, $message);
$sent_mail = true;
}
?>
最后:
<?php
if (isset($sent_mail)) {
echo 'Thank you. We will be in touch soon.';
}
?>
因此,当发送电子邮件时,sent_mail 设置为“true”,因此应回显感谢信息。但现在这行不通。电子邮件先发送,但未显示感谢信息。当提交按钮被按下时,我基本上只需要一条感谢信息出现在页面上的某个位置。
有什么想法吗?
【问题讨论】:
-
这三个代码都在同一个文件中吗?我不认为。我希望表单和“谢谢”在同一个文件中,邮件代码在另一个文件中。你能更新代码位置/文件吗?
-
它们都在同一个文件contactus.php中
-
你能更新完整的文件内容吗?将两个 php 代码保存在单个 框架内。它有效。
-
我在我的服务器上测试了你的代码,它运行良好。我没有发现任何问题。显示您的完整文件代码,因为问题不在于这个。
-
Form message alert的可能重复