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:

  1. You have XAMPP installed on your system.
  2. You have a basic understanding of PHP and MySQL.

Step 1: Enable the mail server in XAMPP

  1. Open the XAMPP Control Panel.
  2. Click on the "Config" button next to "Apache" and select "httpd.conf" from the dropdown menu.
  3. 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.
  4. Save the changes to the file.

Step 2: Configure the mail server

  1. 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).
  2. Search for the line that starts with SMTP. Uncomment the line by removing the ; symbol.
  3. Set the SMTP_HOST and SMTP_PORT values to your desired mail server settings. For example:
    SMTP = localhost
    SMTP_PORT = 25
  4. Save the changes to the file.

Step 3: Configure the mail server in PHP

  1. Open the "php.ini" file again.
  2. Search for the line that starts with sendmail_path. Uncomment the line by removing the ; symbol.
  3. Set the sendmail_path value to the path of the sendmail executable. For example:
    sendmail_path = "C:\xampp\sendmail\sendmail.exe"
  4. Save the changes to the file.

Step 4: Start the mail server

  1. Open the XAMPP Control Panel.
  2. Click on the "Start" button next to "Apache" to start the Apache server.
  3. Wait for the Apache server to start successfully.
  4. 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).
  5. Run the following command to start the sendmail server:
    sendmail -bd -f /var/run/sendmail.pid
  6. You should see a message indicating that the sendmail server is running.

Step 5: Test the mail server

  1. 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.