How to enable mail server in xampp
Enabling the mail server in XAMPP is a bit of a process, but I'll guide you through it. Here are the steps:
Prerequisites:
- You have XAMPP installed on your system.
- You have a basic understanding of PHP and MySQL.
Step 1: Enable the mail server in XAMPP
- Open the XAMPP Control Panel.
- Click on the "Config" button next to "Apache" and select "httpd.conf" from the dropdown menu.
- In the "httpd.conf" file, search for the line that starts with
#LoadModule mail_module modules/mod_mail.so
. Remove the#
symbol to uncomment the line. - Save the changes to the file.
Step 2: Configure the mail server
- Open the "php.ini" file in a text editor. You can find it in the "C:\xampp\php" directory (on Windows) or "/opt/lampp/etc/php.ini" (on Linux/Mac).
- Search for the line that starts with
SMTP
. Uncomment the line by removing the;
symbol. - Set the
SMTP_HOST
andSMTP_PORT
values to your desired mail server settings. For example:SMTP = localhost SMTP_PORT = 25
- Save the changes to the file.
Step 3: Configure the mail server in PHP
- Open the "php.ini" file again.
- Search for the line that starts with
sendmail_path
. Uncomment the line by removing the;
symbol. - Set the
sendmail_path
value to the path of the sendmail executable. For example:sendmail_path = "C:\xampp\sendmail\sendmail.exe"
- Save the changes to the file.
Step 4: Start the mail server
- Open the XAMPP Control Panel.
- Click on the "Start" button next to "Apache" to start the Apache server.
- Wait for the Apache server to start successfully.
- Open a new terminal or command prompt window and navigate to the "C:\xampp\sendmail" directory (on Windows) or "/opt/lampp/sendmail" (on Linux/Mac).
- Run the following command to start the sendmail server:
sendmail -bd -f /var/run/sendmail.pid
- You should see a message indicating that the sendmail server is running.
Step 5: Test the mail server
- Create a new PHP file in your XAMPP project directory with the following code:
<?php $to = '[email protected]'; $subject = 'Test email'; $message = 'This is a test email';
mail($to, $subject, $message); ?>
2. Save the file and open it in a web browser.
3. The email should be sent successfully and you should receive it in your email client.
That's it! You have now enabled the mail server in XAMPP.