Send Email from localhost using XAMPP for Windows

I have search from the Internet on this problem, as a web developer you may face this problem, many solutions out there but this is the that work for me, so I decided to write it and share it.

To Send Email from your localhost computer with authentication required from mail server, please follow this simple steps, on my configuration my XAMPP is located on:

C:\xampp\

 

1. Modify sendmail.ini

The configuration file is located at C:\xampp\sendmail\sendmail.ini, and please have a look on 4 variables, they are :

  • smtp_server
  • smtp_port
  • auth_username
  • auth_password

Find them, and change the value, here is the example:

smtp_port=26

smtp_server=mail.yourdomain.com

; smtp port (normally 25)

smtp_port=26

; SMTPS (SSL) support
; auto = use SSL for port 465, otherwise try to use TLS
; ssl = alway use SSL
; tls = always use TLS
; none = never try to use SSL

smtp_ssl=none

auth_username=eka@yourdomain.com
auth_password=yourpassword

 

 

2. Modify your php.ini

Open your php.ini from XAMPP control panel or locate your self, its located on C:\xampp\apache\bin\php.ini,

and please search sendmail_path variable, and simple uncomment that line.

sendmail_path = “C:\xampp\sendmail\sendmail.exe -t”

 

That’s all. and lets do the testmail.

Here simple php script to test your localhost php.

<?php
$from_name = “Eka”;
$from_email = “eka@mydomain.com”;
$headers = “From: $from_name <$from_email>”;
$body = “Hi, \nThis is a test mail from $from_name <$from_email>.”;
$subject = “Test mail from Eka”;
$to = “somewhere@mydomain.com”;

if (mail($to, $subject, $body, $headers)) {
echo “success!”;
} else {
echo “fail…”;
}
?>

 

Leave a Reply

Your email address will not be published. Required fields are marked *