Surjya Narayana Padhi
Surjya Narayana Padhi

Reputation: 7841

how to send email from Apache server by PHP script

I have installed Apache and PHP on my Windows 7 PC. I learning the PHP now. Following is my PHP script to send email.

<?php
    if(isset($_REQUEST['email']))
    {
        $email = $_REQUEST['email'];
        $subject = $_REQUEST['subject'];
        $message = $_REQUEST['message'];
        mail("[email protected]","$subject","$message","From:","$email");
        echo "Thank you for using the email !!!";
    }
    else
    {
        echo "Mail is not set properly. Please fill the form properly";
    }
?>

I am using a html form to get the required parameters for sending email. Following is the error I am getting while I send the email.

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:\WebLearn\Apache-2.2\htdocs\SimpleWebsite\contact.php on line 7

Do I need to set anything to set in php.ini file or in httpd.conf? If yes how to configure it? Do I need an additional SMTP server on my PC to send email? Please suggest the necessary steps to send an email from my local PC.

Upvotes: 5

Views: 20054

Answers (1)

Borealid
Borealid

Reputation: 98479

The message is saying that it's trying to deliver the email to localhost:25, and there's nothing listening there.

PHP cannot email "the Internet" directly. The message must go to a mail server program such as Postfix or Sendmail or SSMTP, which then relays it to the appropriate destination.

You must install and configure a mail server program and set PHP to use it via php.ini. I believe you also have the option of configuring PHP to use a Sendmail binary instead of SMTP delivery.

Upvotes: 6

Related Questions