I have a code for sending emails through PHP via Gmail SMTP.
But when I submit it has an error, it is being failed from sending.
So can someone help me with the code?
if(isset($_POST['name']))
{
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$exp=$_POST['exp'];
$host = "ssl://smtp.gmail.com";
$username = "email@gmail.com";
$password = "password";
$port = "465";
$to = "me@gmail.com";
$subject = "Contact Form";
$message = " Name: " . $name ."\r\n Email: " . $email . "\r\n Number: " . $phone . "\r\n Driving Experience:" . $exp ;
$from = "" .$name. "( Driver )";
$headers = "From:" . $from . "\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8" . "\r\n";
if(@mail($to,$subject,$message,$headers))
{
$text = "<span style='color:blue; font-size: 35px; line-height: 40px; margin: 10px;'>Your Message was sent successfully !</span>";
}
else
{
$text = "<span style='color:red; font-size: 35px; line-height: 40px; margin: 10px;'>Failed to send your request. Please try again Later.</span>";
}
}
?>
Thanks!