I am designing a PHP page to send an email. An error is occurring. Please check my code carefully and let me know the error in my code.
This is the output which is generated when i run my program:
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
so pls help me to set smtp configuration.
change $header
to $headers
, you've got $headers = "From: $from ";
and using $header
mail($to, $subject, $message,$headers);
so whole code would look like
<?php
//change this to your email.
$to = "kuntal.pushpendra@gmail.com";
$from = "puskun.pericent@gmail.com";
$subject = "Hello! This is HTML email";
$message = "hello";
$headers = "From: $from
";
$headers .= "Content-type: text/html
";
mail($to, $subject, $message,$headers);
echo "Message has been sent....!";
?>
Your mail() function is using $header instead of the variable $headers.
Try mail($to, $subject, $message,$headers);
instead.
You need to setup a mail server (an SMTP one), in order to enable your server to send email. Another way to do that, is to use someone else's mail server, like your' company's, or even the Gmail ones.
A good library to abstract the server SMTP connection is Swift Mailer. It's a robust and well known mailer library, used in projects like symfony.