javascript - 发送邮件后php成功消息不起作用
问题描述
在contact.php 中,我编写了一个表单来获取详细信息,并将提交给contactprocess.php。在我想显示成功消息并重定向到contact.php 的邮件之后。在此代码中,邮件已成功发送,但警报和重定向不起作用。
联系人.php
<form class="form-contact contact_form" action="contact_process.php" method="post" id="contactForm" novalidate="novalidate">
<div class="row">
<div class="col-12">
<div class="form-group">
<input class="form-control" name="subject" id="subject" type="text" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter Subject'" placeholder="Subject">
</div>
</div>
<div class="col-12">
<div class="form-group">
<textarea class="form-control w-100" name="message" id="message" cols="30" rows="9" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter Message'" placeholder="Message"></textarea>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input class="form-control valid" name="name" id="name" type="text" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter your name'" placeholder="name">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input class="form-control valid" name="email" id="email" type="email" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter email address'" placeholder="Email">
</div>
</div>
</div>
<div class="form-group mt-3">
<button type="submit" class="button button-contactForm boxed-btn">Send</button>
</div>
</form>
contact_process.php
<?php
$to = "nomela2170@aieen.com";
$from = $_REQUEST['email'];
$name = $_REQUEST['name'];
$csubject = $_REQUEST['subject'];
$cmessage = $_REQUEST['message'];
$headers = "From: $from";
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $from . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$subject = "You have a message.";
$logo = 'img/logo.png';
$link = '#';
$body = "<!DOCTYPE html><html lang='en'><head><meta charset='UTF-8'><title>Express Mail</title></head><body>";
$body .= "<table style='width: 100%;'>";
$body .= "<thead style='text-align: center;'><tr><td style='border:none;' colspan='2'>";
$body .= "</td></tr></thead><tbody><tr>";
$body .= "<td style='border:none;'><strong>Name:</strong> {$name}</td>";
$body .= "<td style='border:none;'><strong>Email:</strong> {$from}</td>";
$body .= "</tr>";
$body .= "<tr><td style='border:none;'><strong>Subject:</strong> {$csubject}</td></tr>";
$body .= "<tr><td></td></tr>";
$body .= "<tr><td colspan='2' style='border:none;'><strong>Message:</strong>{$cmessage}</td></tr>";
$body .= "</tbody></table>";
$body .= "</body></html>";
if(mail($to, $subject, $body, $headers))
{
echo "<script>alert('successfully sent.'); window.location.href='contact.php';</script>";
}
?>
解决方案
尝试为此留下 PHP 标记:
?>
<script type="text/javascript">
alert("successfully sent");
window.location.href = "contact.php";
</script>
<?php
推荐阅读
- fifo - LRU 页面替换 vs FIFO 页面替换
- json - 翻译和开发人员之间的内部化、工作流程
- java - HashSet 计数比较 Java
- python - 如何在两个 Pandas 数据帧中找到元素调和平均值
- javascript - React Native 代码突然停止工作
- git - 从 Bitbucket 导入存储库时出现 SSL 错误
- python - 错误 126:无法打开 Dll“python34.dll”
- java - 如何从多个 csv 文件中获取 id 和外部 id
- c++ - 什么是 2 pass 和 1 pass 哈希表
- powerapps - 能否在 Power Platform 外部访问 Common Data Service/Dataverse 数据?