0

While I was running my mail code, it shown some errors that I didn't got how to fix... 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']))
{
 $cname = $_POST['name'];

 $email = $_POST['email'];
 $mob = $_POST['mobile'];
 $query = $_POST['message'];
 $subject="Enquiry";
 $message="Name : $cname \n  email : $email \n  Message : $query \n";
 $email_from = 'NAME1<NAME1@email.com.com>';
 $subject = "registration";
 $message = "You have received a new message from the user <b> $cname. </b> \n". "Here is the message:\n $message".
 $to = "name<name@gmail.com>";
 $headers = "From: $email_from \r\n";
 $headers.= "Reply-To: $email \r\n";
    if(mail($to, $subject, $message, $headers))
    {
     echo "<script>alert('Dear User, You Are Successfully Registered')</script>";
    }
}
?>

Note: I have replaced my original email id with name email id. However the Original code has valid email ids. Error:

Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\abc.php on line 29

I'm kinda stuck here well I'm a begginer... Thanks in advance for help...

Ansh
  • 146
  • 1
  • 8
  • 2
    Does this answer your question? [Failed to connect to mailserver at "localhost" port 25](https://stackoverflow.com/questions/4532486/failed-to-connect-to-mailserver-at-localhost-port-25) – Burhan Kashour Oct 18 '20 at 13:59

2 Answers2

0

Please use smtp mail for production release. I'm sharing a link hope it helpful.

https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/

The issue most probably because you're trying to send mail from localhost.

0

I guess the localhost setting are not configurated corretly. You could solve your problem following this issue:

php function mail() isn't working

Regards!

Sones1
  • 123
  • 10