How to send email from Apache server using PHP script

I installed Apache and PHP on my Windows 7 PC. I am learning PHP now. Next up is my PHP script to send email.

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

I use the html form to get the necessary parameters for sending email. Below is the error that I receive while I am sending an email.

Warning: mail () [function.mail]: Failed to connect to the mail server in "localhost" 25, check the settings for "SMTP" and "smtp_port" in php.ini or use ini_set () in C: \ WebLearn \ Apache-2.2 \ htdocs \ SimpleWebsite \ contact.php on line 7

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

+4
source share
1 answer

The message says that he is trying to deliver an email to localhost: 25 and is not listening there.

PHP cannot send "Internet" emails directly. The message should go to a mail server program such as Postfix or Sendmail or SSMTP, which then forwards it to the appropriate destination.

You need to install and configure the mail server program and install PHP for use through php.ini. I believe that you also have the option to configure PHP to use the Sendmail binary file instead of SMTP delivery.

+6
source

Source: https://habr.com/ru/post/1392300/


All Articles