如何解决在 Php 中发送电子邮件页面未正确加载后
我使用 PHP mail() 发送电子邮件。使用此功能邮件正在正确发送。但是发送邮件后页面没有正确加载。实际上我想在发送电子邮件后登陆同一页面。 以下是我写的代码
if (isset($_POST['submit'])) { // Check if form was submitted
if (empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['subject']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) {
echo "No arguments Provided!";
return false;
}
$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$subject = strip_tags(htmlspecialchars($_POST['subject']));
$message = strip_tags(htmlspecialchars($_POST['message']));
// Create the email and send the message
$to = 'myemail@gmail.com'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - This is where the form will send a message to.
$email_subject = "Subjet : $subject";
$email_body = "You have received a new message from your website contact form.\n\n" . "Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From: myemail@gmail.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@gmail.com.
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
header("Refresh:0");
return true;
// exit();
}
这是联系我们页面
解决方法
可能是邮件发送失败。
您可以通过在 PHP 文件顶部添加以下内容来查看它返回的错误:
ini_set('display_errors',1);
另外,建议使用 PHPMailer,因为 mail()
函数并不总是有效。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。