首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在电子邮件消息发送后使php重定向?

如何在电子邮件消息发送后使php重定向?
EN

Stack Overflow用户
提问于 2017-06-19 18:29:14
回答 4查看 7.3K关注 0票数 0

因此,我试图在提交表单到主页后进行重定向。好吧,它是有效的,但有一个问题。当用户按下“提交”按钮时,消息不会显示,但会立即重定向到主页。我如何才能让用户首先收到“谢谢”消息,然后被重定向到主页?

代码语言:javascript
运行
复制
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];

$mail_to = 'vladozabunov@gmail.com';
$subject = 'Message from a site visitor '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
  <script language="javascript" type="text/javascript">
    alert('Thank you for the message. We will contact you shortly.');
    window.location = 'contact_page.html';
  </script>
  <?php
}
else { ?>
    <script language="javascript" type="text/javascript">
      alert('Message failed. Please, send an email to gordon@template-help.com');
      window.location = 'contact_page.html';
    </script>
    <?php
}
header('Location: https://saprs.000webhostapp.com/index.html');
?>
EN

Stack Overflow用户

发布于 2017-06-19 18:34:23

代码语言:javascript
运行
复制
$mail_to = 'vladozabunov@gmail.com';
$subject = 'Message from a site visitor '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);
if($mail_status == true){
    echo "<script>alert('Thank you for the message. We will contact you shortly.');</script>";
    header('Location:https://saprs.000webhostapp.com/contact_page.html');
}else{
    echo "<script>alert('Sorry! Please try again.');</script>";
    header('Location:https://saprs.000webhostapp.com/contact_page.html');
}
票数 0
EN
查看全部 4 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44628146

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档