Can send mail in php from localhost

Sending mail from a PHP script on a local machine (localhost) can be a bit tricky, but it's definitely possible. Here are the general steps:

Step 1: Set up a mail server on your local machine

You'll need to set up a mail server on your local machine to send and receive emails. There are several options available, including:

Step 2: Configure your PHP script to use the mail server

Once you have set up a mail server on your local machine, you'll need to configure your PHP script to use it. You can do this by setting the SMTP and smtp_port variables in your PHP script:

<?php
ini_set('SMTP', 'localhost');
ini_set('smtp_port', 1025);
?>

Replace localhost with the hostname or IP address of your mail server, and 1025 with the port number used by your mail server.

Step 3: Send the email

Now that your PHP script is configured to use the mail server, you can send an email using the mail() function:

<?php
$to = '[email protected]';
$subject = 'Test email';
$message = 'This is a test email';

mail($to, $subject, $message);
?>

This will send an email to the recipient with the specified subject and message.

Troubleshooting tips

If you're having trouble sending emails from your PHP script on localhost, here are a few things to check: