0

i am using simple send email in php and get this error

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 587, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in

<?php
//if "email" variable is filled out, send email
  if (isset($_REQUEST['email']))  {

  //Email information
  $admin_email = "Silicon.abhishekp@gmail.com";
  $email = $_REQUEST['email'];
  $subject = $_REQUEST['subject'];
  $comment = $_REQUEST['comment'];

  //send email
  mail($admin_email, "$subject", $comment, "From:" . $email);

  //Email response
  echo "Thank you for contacting us!";
  }

  //if "email" variable is not filled out, display the form
  else  {
?>

 <form method="post">
  Email: <input name="email" type="text" /><br />
  Subject: <input name="subject" type="text" /><br />
  Message:<br />
  <textarea name="comment" rows="15" cols="40"></textarea><br />
  <input type="submit" value="Submit" />
  </form>

<?php
  }
?>
Abhishek
  • 320
  • 4
  • 17

1 Answers1

0

SMTP server is required for sending emails. You need to mention SMTP host and SMTP port in php.ini file. If your config is proper then the mail function will work. There are various SMTP servers are available. You can search for them.

Kinshuk Lahiri
  • 1,468
  • 10
  • 23