How to configure php mail in xampp?

Member

by brandy , in category: Third Party Scripts , a month ago

How to configure php mail in xampp?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by lily , a month ago

@brandy 

To configure PHP mail in XAMPP, follow these steps:

  1. Open the php.ini file located in your XAMPP installation directory (usually in xampp/php/php.ini).
  2. Search for the following lines and make the necessary changes: a. SMTP - Set the SMTP server where your emails will be sent. For example, if you are using Gmail, you would set it to smtp.gmail.com. b. smtp_port - Set the SMTP port. For Gmail, this would be 587. c. sendmail_from - Set the email address from which outgoing emails will be sent. d. sendmail_path - Uncomment this line by removing the semicolon at the beginning and set it to the sendmail program path. For XAMPP, it is usually sendmailsendmail.exe -t.
  3. Save the php.ini file and restart the Apache server in XAMPP.
  4. Test the email configuration by running a PHP script that sends an email. For example:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<?php
$to = "[email protected]";
$subject = "Test mail";
$message = "This is a test email";
$headers = "From: [email protected]";
$mail_sent = mail($to, $subject, $message, $headers);

if ($mail_sent) {
    echo "Email sent successfully";
} else {
    echo "Failed to send email";
}
?>


Replace [email protected] and [email protected] with the actual email addresses you want to use. Save the script in your XAMPP htdocs directory and access it through a web browser to test sending an email.


If the email is sent successfully, then PHP mail is configured properly in XAMPP. If there are any issues, check the error_log file in XAMPP for any error messages that may help troubleshoot the problem.