I created a contact form in PHP, but it is not sending emails from my website.
My contact form doesn't work perfectly, and after uploading it to a live server like cPanel or hPanel, emails are not being delivered. When a user submits the contact form, the form is submitted successfully, but I don't receive any emails in my inbox.
I have tried using the PHP mail() function, but it is not working on my hosting server. I also contacted my hosting provider, but they couldn't resolve my problem.
I am using Hostinger hPanel and GoDaddy cPanel hosting.
if(isset($_POST['sub']))
{
$name=$_POST['name'];
$email=$_POST['email'];
$msg=$_POST['msg'];
$phone=$_POST['phone'];
$FromName="My Website Title";
$FromEmail="info@mywebsite.com";
$ReplyTo=$email;
$toemail="mytoemail@gmail.com";
$subject="Contact Form";
$message='Name:-'.$name.'<br>Email :-' .$email.'<br> Phone No:-'.$phone.'<br> Message:-'.$msg;
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "From: ".$FromName." <".$FromEmail.">\n";
$headers .= "Reply-To: ".$ReplyTo."\n";
$headers .= "X-Sender: <".$FromEmail.">\n";
$headers .= "X-Mailer: PHP\n";
$headers .= "X-Priority: 1\n";
$headers .= "Return-Path: <".$FromEmail.">\n";
if(mail($toemail, $subject, $message, $headers,'-f'.$FromEmail) ){
$hide=1;
echo 'Sent';
} else {
echo "Failed";
}
}
How can I send emails from a PHP contact form using PHP SMTP?
Why is my PHP contact form not sending emails?
How do I fix the PHP contact form email not working issue on cPanel or hPanel hosting?