html - PHP mailserver failure

While I was working with html and php for sending mail via forms, I found this error. My code:
<!doctype html>
<html>
<body>
<form method="post" action="#">
<input type='text' name='name'>
<input type='email' name="email">
<input type="number" name="mobile">
<input type="text" name="message">
<input type="submit" name='submit'>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
$mob = $_POST['mobile'];
$email = $_POST['email'];
$subject="Enquiry";
$query = $_POST['message'];
{
$cname = $_POST['name'];
$message="Name : $cname \n email : $email \n Message : $query \n";
$email_from = 'person2<[email protected]>';
$subject = "registration";
$message = "You have received a new message from the user <b> $cname. </b> \n". "Here is the message:\n $message".
$to = "person1<[email protected]>";
$headers = "From: $email_from \r\n";
$headers.= "Reply-To: $email \r\n";
ini_set("SMTP", "ssl://smtp.gmail.com");
ini_set("smtp_port", "587");
ini_set("sendmail_from", "[email protected]");
if(mail($to, $subject, $message, $headers))
{
echo "<script>alert('Dear User, You Are Successfully Registered')</script>";
}
else
{
echo "It was a problem!";
}
}
?>
Error:
Warning: mail(): Failed to connect to mailserver at "ssl://smtp.gmail.com" port 587, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
I tried many websites and answers to similar question in this only but I could not understand anything. Can anyone please tell me the cause and solution?
Answer
Solution:
Try connecting to the mailserver again and as it says check you SMPT in your php file
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: object of class stdclass could not be converted to string
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.