Contact form php

Hello, I have a contact form my website that would like to send mail directly to my email. I tried sending it but its not working what could be the problem?

<?php
 if(isset($_POST['submit'])){
 	$name=$_POST['name'];
 	$email=$_POST['email'];
 	$subject=$_POST['subject'];
 	$message=$_POST['message'];

 	$to='lappyodhiambo@gmail.com';
 	$subject='Form Submission';
 	$message="Name : ".$name."\n"."Email :".$email."\n". "Wrote the following: "."\n\n".$message;
 	$headers="From: ".$email;

 	if (mail($to, $subject, $message, $headers)) {
 		echo "<h3> Sent Successfully ! Thank You"."".$name.", we Will contact you later </h3>";
 	}
 	else {
 		echo "something went wrong";
 	}
 }
 ?>

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

Please use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks are not single quotes.

markdown_Forums

Here is the form in html

<form method="POST" id="contactForm" class="contactForm" action="php/contact_form.php">
											<div class="row">
												<div class="col-md-6">
													<div class="form-group">
														<input type="text" class="form-control" name="name" id="name" placeholder="Name">
													</div>
												</div>
												<div class="col-md-6"> 
													<div class="form-group">
														<input type="email" class="form-control" name="email" id="email" placeholder="Email">
													</div>
												</div>
												<div class="col-md-12">
													<div class="form-group">
														<input type="text" class="form-control" name="subject" id="subject" placeholder="Subject">
													</div>
												</div>
												<div class="col-md-12">
													<div class="form-group">
														<textarea name="message" class="form-control" id="message" cols="30" rows="7" placeholder="Message"></textarea>
													</div>
												</div>
												<div class="col-md-12">
													<div class="form-group">
														<input type="submit" name="submit" value="Send Message" class="btn btn-primary">
														<div class="submitting"></div>
													</div>
												</div>
											</div>
										</form>

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

Please use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks are not single quotes.

markdown_Forums

Describe what you mean by not working. What are you expecting the code vs. what it does do? Are you seeing any errors in the server logs or the browser console?

Hi,

Did you try to send message also from live server?
Because my host provider also use PHP back-end. I have gmail as well.
I am able to send message from the server to my mailbox BUT the exactly same code does not works from localhost. If you are unable to try your code on live server, then you have to check your PHP.ini file:
Look these code:

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP_server=smtp.gmail.com
; http://php.net/smtp-port
smtp_port=587
auth_username=<yourmail@gmail.com>
auth_password=<your password>

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = <yourmail@gmail.com>

If you find the correct settings please let me know. I also not able to send mail from localhost…

I am not able to receive the email that is