1 回答

TA贡献1848条经验 获得超2个赞
在 HTML 提交按钮上命名:
<input type="submit" name="submit" value="SEND MESSAGE" class="button medium gray" data-loading-text="Loading...">
编辑:
首先,把你的决赛
if
放在$_POST['submit']
if
. 您只在提交时才这样做,并且$mail_status
只在其中设置:使用
$_GET
params,而不是#
... 那些用于滚动到名称相同的锚点。将 index.html 转换为 index.php,以便您可以
DIV
使用 PHP控制要显示的内容。
$result = $_GET['result']
将在 URL 中的 = 之后包含任何内容 ?result=
那么
if($result == 'success') {
?> <!-- Show Success Div --> <?php
} else {
?><!-- Show error DIV --> <?php
这是您的 PHP,其中更改了重定向 URL 以使用$_GET参数并index.html转换为 PHP:
<?php
if (isset($_POST['submit'])) {
$to = "bbbbb@gmail.com";
$from = $_POST['email'];
$first_name = $_POST['name'];
$subject = "Form submission";
$message = $first_name . " " . " wrote the following:" . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$mail_status = mail($to, $subject, $message, $headers);
if ($mail_status) {
?>
<script language="javascript" type="text/javascript">
window.location.href = 'index.php?result=success';
</script>
<?php
} else {
?>
<script language="javascript" type="text/javascript">
window.location.href = 'index.php?result=failed';
</script>
<?php
}
}
?>
- 1 回答
- 0 关注
- 151 浏览
添加回答
举报