How to configure xampp to send mail from localhost mac

To configure XAMPP to send mail from localhost on a Mac, you'll need to set up a mail server and configure XAMPP to use it. Here's a step-by-step guide:

Step 1: Install and configure a mail server

You can use a mail server like Postfix or Mailhog. For this example, we'll use Mailhog.

  1. Install Mailhog using Homebrew: brew install mailhog
  2. Start Mailhog: mailhog start
  3. Open a web browser and navigate to http://localhost:8025 to access the Mailhog dashboard.

Step 2: Configure XAMPP to use Mailhog

  1. Open the XAMPP control panel and navigate to the "Config" tab.
  2. Click on "PHP Settings" and then click on the "Mail" tab.
  3. Set the following settings:
    • SMTP Host: localhost
    • SMTP Port: 1025 (or the port number specified in Mailhog's settings)
    • SMTP User: [email protected] (replace with your email address)
    • SMTP Password: your_email_password (replace with your email password)
    • SMTP Encryption: none (or ssl or tls depending on your mail server settings)
  4. Click "Save" to save the changes.

Step 3: Test the mail configuration

  1. Create a PHP file with the following code:

    <?php
    $mail = new PHPMailer();
    $mail->isSMTP();
    $mail->Host = 'localhost';
    $mail->Port = 1025;
    $mail->SMTPAuth = true;
    $mail->Username = '[email protected]';
    $mail->Password = 'your_email_password';
    $mail->setFrom('[email protected]', 'Your Name');
    $mail->addAddress('[email protected]', 'Recipient Name');
    $mail->Subject = 'Test email from XAMPP';
    $mail->Body = 'This is a test email from XAMPP';
    $mail->send();
    ?>

    Replace the email addresses and passwords with your own.

  2. Open a terminal and navigate to the directory where you created the PHP file.

  3. Run the PHP file using the command php test.php (replace test.php with the name of your PHP file).

  4. Check the Mailhog dashboard to see if the email was sent successfully.

That's it! You should now be able to send emails from your XAMPP setup on your Mac using Mailhog as the mail server.