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.
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.
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: