I'm trying to send form data to my E-mail with no success. I want that when the user click on "submit" button (and after validation) the data field will send to my e-mail and the user see a message "Thank you for contacting us" instead of the form field. I am very new with PHP and hope one of you can help me.
This is my HTML form:
<form id="contactForm" method="post" action="contact.php" onsubmit="return validateForm()">
<input type="text" name="name" id="name" placeholder="Full Name">
<input type="email" name="email" id="email" placeholder="E-mail Address">
<input type="text" name="phone" id="phone" placeholder="Phone Number">
<input type="text" name="company" id="company" placeholder="Company">
<textarea name="message" id="message" placeholder="Write Your Message Here..."></textarea>
<input type="submit" value="SEND" id="submitForm">
</form>
and this is my PHP Code:
<?php
if($_POST["submit"]) {
$recipient="myEmail@gmail.com";
$subject="Message from Website";
$sender=$_POST["name"];
$senderEmail=$_POST["email"];
$senderPhone=$_POST["phone"];
$senderCompany=$_POST["company"];
$message=$_POST["message"];
$mailBody="Name: $sender\nEmail: $senderEmail\nPhone: $senderPhone\nCompany: $senderCompany\n\n$message";
mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>");
$thankYou="<p>Thank you! Your message has been sent.</p>";
}
?>
I also have JS validation function to this form called validateForm() which works fine. Should I need to define something on the hosting server to make this PHP works?