0

I have contact form on my website(hosted with Hostinger) it contains 3 fields , i am trying to receive the message on my email so i have created the HTML tags and .php handler.

The problem is nothing happened when i click submit , here is my HTML and PHP:

HTML:
<form method="POST" action="contact-form-handler.php">
    <label class="nameLabel">Name:        
    <input type="text" name="name" id="name" required>
    </label>
    <label class="emailLabel">Email:
    <input type="email" name="email" id="email" required>
    </label>
    <label class="messageLabel">Message:
    <textarea class="textarea" name="message" id="message" required>                            
    </textarea>
    </label>
    <input  type="submit" class="button"   value="SEND">
</form>

Here is my .php

<?php
    $name = $_POST['name'];
    $visitor_email = $_POST['email'];
    $message = $_POST['message'];


    $email_from ='email@gmail.com';

    $email_subject ="Form Submission";

    $email_body = "User Name: $name.\n".
                    "User Email: $visitor_email.\n".
                        "User Message: $message.\n";


    $to = "2ndemail@yahoo.com";

    $headers = "From: $email_from \r\n";

    $headers .= "Reply-To: $visitor_email \r\n";

    mail($to,$email_subject,$email_body,$headers);
    header("Location: index.html");
?>
Was
  • 1
  • 4
  • 2
    Possible duplicate of [PHP mail function doesn't complete sending of e-mail](https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail) – CBroe Aug 01 '18 at 11:02
  • Specifying arbitrary `From:` addresses is a sure-fire way to land in the spam filter these days. Don’t do that, unless you are sending via a server that is officially “allowed” (SPF, etc.) to send out emails for the domain in question, or you are at least using SMTP auth to send the mail via that domain’s official mail server. – CBroe Aug 01 '18 at 11:05
  • you didn't add name value – suresh Aug 01 '18 at 11:07
  • @CBroe , I changed the From: to the domain email and perfectly solved my problem !! Thank you – Was Aug 01 '18 at 15:00

0 Answers0