How to configure xampp to send mail from localhost

To configure XAMPP to send mail from localhost, you'll need to set up a mail server and configure your PHP settings. Here's a step-by-step guide to help you achieve this:

Step 1: Install XAMPP

If you haven't already, download and install XAMPP from the official website. Make sure to select the correct version for your operating system (Windows, macOS, or Linux).

Step 2: Install a mail server

XAMPP comes with a built-in mail server called Mercury. However, it's not enabled by default. You'll need to install and configure it manually.

For Windows:

  1. Open the XAMPP Control Panel.
  2. Click on the "Config" button next to "Mercury" under the "Services" tab.
  3. In the "Mercury Configuration" window, select the "Install" option.
  4. Follow the installation prompts to complete the installation.

For macOS/Linux:

  1. Open the terminal and navigate to the XAMPP installation directory (e.g., /opt/lampp).
  2. Run the command sudo./lampp start mercury to start the Mercury mail server.
  3. Run the command sudo./lampp enable mercury to enable the Mercury mail server.

Step 3: Configure PHP

You'll need to configure your PHP settings to use the Mercury mail server. Edit the php.ini file (usually located in the C:\xampp\php directory on Windows or /opt/lampp/etc/php.ini on macOS/Linux) and add the following lines:

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
sendmail_from = [email protected]

Replace [email protected] with your actual email address.

Step 4: Test your mail server

Open a new terminal or command prompt and run the following command to test your mail server:

telnet localhost 25

This should connect you to the Mercury mail server. Type quit to exit the connection.

Step 5: Send a test email

Create a new PHP file (e.g., test.php) with the following code:

<?php
mail('[email protected]', 'Test Email', 'This is a test email');
?>

Replace [email protected] with the email address you want to send the test email to.

Save the file and open it in your web browser. If everything is set up correctly, you should receive an email at the recipient's email address.

That's it! You should now be able to send emails from your localhost using XAMPP and Mercury.