【问题标题】:How do I redirect to an HTML page after submitting a PHP email form?提交 PHP 电子邮件表单后如何重定向到 HTML 页面?
【发布时间】:2013-10-20 00:08:21
【问题描述】:

这是我的代码:

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$formcontent = "From: $name \n Email: $email \n Subject: $subject \n Message: $message";
$recipient = "hunter@dreaminginhd.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
?>

我只需要知道如何在单击提交后重定向到 HTML 页面并确保脚本发送电子邮件。任何帮助将不胜感激!

【问题讨论】:

    标签: php html forms email post


    【解决方案1】:

    首先我们让 mailto 函数与 localhost 和电子邮件客户端一起工作:
    在 stackoverflow 上查看此链接:
    网址链接:send email to owner by collecting information provided by user through form?

    那么我推荐使用 Swiftmailer。 http://swiftmailer.org/docs/sending.html他们得到了最好的手册。

    【讨论】:

      【解决方案2】:

      您可能缺少打开表单和关闭表单,或者您只是包含它

       <form name="PL" action="newForm.php" method="post">
       <?php
       $name = $_POST['name'];  
       $email = $_POST['email'];
      
       $subject = $_POST['subject'];
      
       $message = $_POST['message'];
      
       $formcontent = "From: $name \n Email: $email \n Subject: $subject \n Message:   
       $message";
      
       $recipient = "hunter@dreaminginhd.com";
      
       $subject = "Contact Form";
      
       $mailheader = "From: $email \r\n";
      
       mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");  
      include "newForm2.php";
       ?>
       <input type="submit" name="btn_submit" value="Display Invoice" /> 
       </form>
      

      【讨论】:

      • 要使 mail() 函数正常工作,您的 php.ini 文件需要正确的 SMTP 设置。这也取决于您是通过 POP3 还是 IMAP 发送。
      【解决方案3】:

      php

      header('Location: login.php?msg=1');
      

      javascript

      <script> window.location='forgot.php'</script>";
      

      html

      <META HTTP-EQUIV="REFRESH" CONTENT="3;URL=http://google.com">
      

      【讨论】:

        【解决方案4】:

        将此添加到脚本的末尾:

        header("Location: URL");
        

        URL 是您要重定向到的页面的 URL。

        【讨论】:

        猜你喜欢
        • 2018-11-05
        • 2014-03-10
        • 1970-01-01
        • 2013-11-14
        • 2021-09-20
        • 1970-01-01
        • 2013-09-16
        • 2017-10-28
        • 2019-05-27
        相关资源
        最近更新 更多