<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];

$mailheader = "From:sumitlanjewar21@gmail.com \r\n";

$recipient = $_POST['email'];
$receiver = $email;
// $subject = "Email Test via PHP using Localhost";
$body = $message ;
$sender = mail ($receiver, $subject, $message, $mailheader);
if(is_null($receiver)!=true){
    // echo "Email sent successfully to $receiver";
    echo("<script>console.log('head: " . $mailheader . "');</script>");
    echo("<script>console.log('body: " . $message . "');</script>");
    echo("<script>console.log('subject: " . $subject . "');</script>");
    echo("<script>console.log('receiver: " . $receiver . "');</script>");
    echo'

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Contact form</title>
    <link href="https://fonts.googleapis.com/css2?family=Playfair+Display:wght@600&family=Poppins&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="container">
        <h1>Thank you for contacting me. I will get back to you as soon as possible!</h1>
        <p class="back">Go back to the <a href="index.html">homepage</a>.</p>
        
    </div>
</body>
</html>
';
}else{
    echo("<script>console.log('head: " . $mailheader . "');</script>");
    echo("<script>console.log('body: " . $message . "');</script>");
    echo("<script>console.log('subject: " . $subject . "');</script>");
    echo("<script>console.log('receiver: " . $receiver . "');</script>");
    echo "Sorry, failed while sending mail!";
    echo "Email sent successfully to $mailheader";
    echo "check $sender";
    echo("<script>console.log('sender: " . $sender . "');</script>");
}
?>