0

i have installed Apache and php5 on windows 8.1, but can't send mail from my localhost website, the message that appears "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() in C:\WebServer\Apache2.2\htdocs\WebContent\mailForm.php on line 22". The php code is below, i guess it's ok since it does the 'echos' correctly. Someone can give any tips about what's happening? Thanks.

    <?php
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$message = $_POST['message'];

$to = "myemail@example.com";
$subject = "New_message";


if (($first_name == "") || ($last_name == "") || ($email == "") || ($message == ""))
{
echo '<script type="text/javascript">alert("Fill in all fields")</script>';
}
else
{
    mail($to, $subject, $message, "From:" . $first_name . $last_name);
echo "Sucess;
}
?>
Miguel
  • 1,579
  • 5
  • 18
  • 31

1 Answers1

0

Are you sure there is a mail server running on the host where your PHP is running? You mentioned that you installed apache and PHP, but you did not mention that you installed a mail server. If there is no mail server installed, then that's your problem.

If there is in fact a mail server running on the host, then it means that PHP is not configured correctly to find it. Create a small script like below, which uses phpinfo() to print out all of your PHP environment variables:

<? phpinfo(); ?>

Check the value of sendmail_path. Is this the correct location of the mail server on the host? If not, change your php.ini to point to the correct location.

If in fact there is not a mail server running on the host, then you can either install one, or you can work around the problem by sending mail through a mail server hosted elsewhere (such as smtp.gmail.com if you have a gmail account). This can be done using phpmailer. See send email using Gmail SMTP server through PHP Mailer as an example.

Community
  • 1
  • 1
mti2935
  • 11,465
  • 3
  • 29
  • 33