-1

am having html form with name , email and message and i want when someone fills in the details and press submit, the info goes to my email. But when i tried it i got an 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\forms\script.php on line 18

here is my html doc

<form method="post" name="myemailform" action="script.php">

Enter Name: <input type="text" name="name">
    
Enter Email Address:    <input type="text" name="email">
   
Enter Message:  <textarea name="message"></textarea>
    
<input type="submit" value="Send Form">
</form>

my php file

<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];

$email_from = 'katojames123@gmail.com';
$email_subject = "New Form submission";

$email_body = "You have received a new message from the user $name.\n".
                        "Here is the message:\n $message";

$to = "katojames248@gmail.com";

$headers = "From: $email_from \r\n";

$headers .= "Reply-To: $visitor_email \r\n";

mail($to,$email_subject,$email_body,$headers);
                      
?>

any help guys

kato james
  • 19
  • 5
  • 3
    What about the error message do you not understand? It basically says that you need to point your php.ini settings to the mailserver you're running. – KIKO Software May 24 '22 at 20:26
  • 1
    Have you verified your "SMTP" and "smtp_port" setting in php.ini? It sounds like the settings are pointing to `localhost`. Are you running a mail server on `localhost`? – David May 24 '22 at 20:29
  • Does this answer your question? [Warning: mail() [function.mail\]: Failed to connect to mailserver](https://stackoverflow.com/questions/7011300/warning-mail-function-mail-failed-to-connect-to-mailserver) – gre_gor May 24 '22 at 20:32
  • Consider this SO thread on sending mail from local host https://stackoverflow.com/questions/15965376/how-to-configure-xampp-to-send-mail-from-localhost – mardubbles May 24 '22 at 20:56

0 Answers0