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.
- Install Mailhog using Homebrew:
brew install mailhog
- Start Mailhog:
mailhog start
- Open a web browser and navigate to
http://localhost:8025
to access the Mailhog dashboard.
Step 2: Configure XAMPP to use Mailhog
- Open the XAMPP control panel and navigate to the "Config" tab.
- Click on "PHP Settings" and then click on the "Mail" tab.
- 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
(orssl
ortls
depending on your mail server settings)
- Click "Save" to save the changes.
Step 3: Test the mail configuration
-
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.
-
Open a terminal and navigate to the directory where you created the PHP file.
-
Run the PHP file using the command
php test.php
(replacetest.php
with the name of your PHP file). -
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.