To send an email with PHP from a XAMPP server, you can use PHP’s built-in mail() function, which is capable of sending simple emails. Here are the steps to set up and send an email using XAMPP:
Install and Start XAMPP:
If you haven’t already, download and install XAMPP. Start the XAMPP control panel and ensure that the Apache and MySQL services are running.
Create Your PHP Script:
Create a PHP script that sends the email. This script will use the mail() function to send the email. For example:
Replace “email@example.com” with the actual recipient’s email address.
Replace “firstname.lastname@example.org” with the sender’s email address.
Customize the email subject and message as needed.
Place the PHP Script in Your XAMPP Web Root:
Save the PHP script in the htdocs directory of your XAMPP installation or in a subdirectory within htdocs.
Access the PHP Script Through Your Web Browser:
Access the PHP script through your web browser by visiting http://localhost/your_project_folder/your_script.php, where your_project_folder is the name of the directory where you placed the PHP script.
For example, if you saved the script directly in the htdocs directory and named it send_email.php, you would access it at http://localhost/send_email.php.
Configure the PHP mail function in XAMPP
Edit the php.ini file:
Locate your php.ini configuration file. In XAMPP, you can find it in the php directory. The path is typically xampp/php/php.ini.
Open php.ini in a text editor (e.g., Notepad).
Configure the SMTP settings:
Search for the [mail function] section in the php.ini file.
Configure the SMTP settings according to your local mail server setup. You can use the SMTP server of your email provider or a local SMTP server if available. Below is an example configuration for using a Gmail SMTP server (you would replace with your own SMTP server information):
[mail function] SMTP = smtp.gmail.com smtp_port = 587 sendmail_from = email@example.com sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
Replace the Gmail-specific values with the SMTP server information from your email provider or your local SMTP server.
Install and configure sendmail (if not already done):
If XAMPP does not come with sendmail, you may need to download and install it. You can download sendmail for Windows from http://glob.com.au/sendmail/.
After installation, configure sendmail.ini (located in the sendmail directory) with your SMTP server settings. Here is an example configuration for Gmail:
smtp_server=smtp.gmail.com smtp_port=587 firstname.lastname@example.org auth_password=your-gmail-password
Replace the Gmail-specific values with your own.
After making changes to the php.ini and sendmail.ini files, restart the Apache web server through the XAMPP control panel for the changes to take effect.
Test the configuration:
Open your web browser and navigate to http://localhost/test_mail.php or the appropriate URL to execute the script and test the mail functionality.
Make sure that you’ve provided the correct SMTP server settings and credentials. If you’re using Gmail, you might need to enable “Less secure apps” in your Google Account settings temporarily to allow the PHP mail script to send emails. However, be cautious when using this setting in a production environment, as it may pose a security risk. In a production environment, consider using a dedicated mail server.