0

Am not having good knowledge in PHP, I have just started to work on it... Now am trying to use mail() function as example given in w3schools.com

<?php
$to = "ramkumarpece05@gmail.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "ramp211087@gmail.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

for this am getting error message as follows

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 F:\contact.ph
p on line 7
Mail Sent.

where the php.ini file is located or i have to download it from the internet.....

Please help me to solve this issue...

Ramkumar P
  • 209
  • 1
  • 2
  • 14

2 Answers2

2

You probably didn't install a mail server on your machine, you can install one for testing purposes (mail from your server will probably be marked as spam) or you can configure PHP to use your email account.

Community
  • 1
  • 1
Nabil Kadimi
  • 10,078
  • 2
  • 51
  • 58
1

Your mail method is fine, your local server isn't. It is attempting to send the email but there is no SMTP server setup on your local server to send the email. You can install programs like Tomcat or Mercury which can handle the sending of the emails. You will just have to provide it some credentials to authenticate. I used my Gmail account's SMTP for example to send emails from my local server.

Dan Hlavenka
  • 3,697
  • 8
  • 42
  • 60
brenjt
  • 15,997
  • 13
  • 77
  • 118