簡體   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