繁体   English   中英

提交联系表后如何重定向到主页?

[英]How to redirect to home page after submitting the Contact Form?

我已经创建了联系表格,但我遇到了两个问题

  1. 回复邮件不去。
  2. 提交表单页面后必须重定向到主页。

作为参考,请找到附加的图像和代码

在此处输入图片说明

下面是PHP代码

<?php
if(isset($_POST['submit']))
{
    $name = $_POST['name']; // Get Name value from HTML Form
    $email_id = $_POST['email']; // Get Email Value
    $mobile_no = $_POST['Mobile']; // Get Mobile No
    $msg = $_POST['message']; // Get Message Value
     
    $to = "somasekhar.n@vitalticks.com"; // You can change here your Email
    $subject = "'$name' has been sent a mail"; // This is your subject
     
    // HTML Message Starts here
    $message ="
    <html>
        <body>
            <table style='width:600px;'>
                <tbody>
                    <tr>
                        <td style='width:150px'><strong>Name: </strong></td>
                        <td style='width:400px'>$name</td>
                    </tr>
                    <tr>
                        <td style='width:150px'><strong>Email ID: </strong></td>
                        <td style='width:400px'>$email_id</td>
                    </tr>
                    <tr>
                        <td style='width:150px'><strong>Mobile No: </strong></td>
                        <td style='width:400px'>$mobile_no</td>
                    </tr>
                    <tr>
                        <td style='width:150px'><strong>Message: </strong></td>
                        <td style='width:400px'>$msg</td>
                    </tr>
                </tbody>
            </table>
        </body>
    </html>
    ";
    // HTML Message Ends here
     
    // Always set content-type when sending HTML email
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

    // More headers
    $headers .= "From: New Contact Form <".$_POST["email"].">\r\n"; // Give an email id on which you want get a reply. User will get a mail from this email id
    $headers .= 'Cc: somumstr210@gmail.com' . "\r\n"; // If you want add cc
   // $headers .= 'Bcc: somasekhar.n@vitalticks.com' . "\r\n"; // If you want add Bcc
    $headers .= "Reply-To: ".$_POST["email"]."\r\n";
     
    if(mail($to,$subject,$message,$headers)){
        // Message if mail has been sent
        echo "<script>
                alert('Mail has been sent Successfully.');
            </script>";
    }

    else{
        // Message if mail has been not sent
        echo "<script>
                alert('EMAIL FAILED');
            </script>";
    }
}
?>
  1. 邮件功能已弃用,可能无法正常工作! 我推荐 phpmailer https://github.com/PHPMailer/PHPMailer

  2. 如何在 PHP 中进行重定向?

    header("位置:路径/到/文件");

  3. 请检查帖子变量

    $variable = $_POST['变量名'] ?? "如果 $_POST['variable-name'] 未定义,则默认内容";

编辑:mail() 没有被弃用,但请使用 PHPmailer,因为它更好

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM