-1

i have created contact form but i am getting two problems

  1. Reply-To mail is not going.
  2. After Submitting the form page has to redirect to Home page.

For reference please find the attached image and code

enter image description here

Below is the PHP code

<?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>";
    }
}
?>
Felippe Duarte
  • 14,901
  • 2
  • 25
  • 29
somutesting
  • 289
  • 1
  • 5
  • 17

1 Answers1

0
  1. The mail function is deprecated and may not work right! I recommand phpmailer https://github.com/PHPMailer/PHPMailer

  2. How do I make a redirect in PHP?

    header("Location: path/to/file");

  3. please check post variables

    $variable = $_POST['variable-name'] ?? "default content if $_POST['variable-name'] is undefined";

EDIT: mail() is not deprecated but please use the PHPmailer because it's better