How I can send emails to gmail, yahoo, etc. from localhost.

I am using XAMPP in windows.
What are the necessary changes in php.ini ??

Member Avatar for diafol

You need to set up your local machine to do that (SMTP). Mercury Mail will allow you to do this. It should be included in the full xampp download for windows.

Hello abhi,

You have to first include the php mailer class in your folder.

hi. here is my tested solution.

you only have to modify 2 ini files: php.ini and sendmail.ini

1)look for mail function in php.ini(c:/xampp/php/php.ini)>>[mail function]

change the following::


sendmail_from =

sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

NOTE: ensure that the path you specify for sendmail_oath is valid.In my case it is in C.
SAVE your changes.

2) next modify sendmail.ini(c:/xampp/sendmail/sendmail.ini)
comment the mercury as shown below

# Mercury
#account Mercury
#host localhost
#from postmaster@localhost
#auth off

# A freemail service example
#account Hotmail
#tls on
#tls_certcheck off
#from [exampleuser]
#auth on
#user [exampleuser]
#password [examplepassword]

then paste the following lines:

account Gmail
tls on
tls_certcheck off
auth on
password x

port 587

# Set a default account
account default : Gmail

Again SAVE your changes.

Use the code below to test if it's working!
$subject="Test mail";
$body="This is a test mail";
if (mail($to,$subject,$body))
echo "Mail sent successfully!";
echo"Mail not sent!";

NOTE in the above configuration the sender should use gmail email service,for the recipient any email service will do.

Hi there mr. novice02!

i followed and tested your post just now, im just confused about the section #2 you specified there, it looks so different in my sendmail.ini file, here are the contents of my sendmail.ini file:

; configuration for fake sendmail

; if this file doesn't exist, sendmail.exe will look for the settings in
; the registry, under HKLM\Software\Sendmail


; you must change to your smtp server,
; or to IIS's "pickup" directory. (generally C:\Inetpub\mailroot\Pickup)
; emails delivered via IIS's pickup directory cause sendmail to
; run quicker, but you won't get error messages back to the calling
; application.


; smtp port (normally 25)


; the default domain for this server will be read from the registry
; this will be appended to email addresses when one isn't provided
; if you want to override the value in the registry, uncomment and modify


; log smtp errors to error.log (defaults to same directory as sendmail.exe)
; uncomment to enable logging


; create debug log as debug.log (defaults to same directory as sendmail.exe)
; uncomment to enable debugging


; if your smtp server requires authentication, modify the following two lines


; if your smtp server uses pop3 before smtp authentication, modify the
; following three lines


; to force the sender to always be the following email address, uncomment and
; populate with a valid email address. this will only affect the "MAIL FROM"
; command, it won't modify the "From: " header of the message content


; sendmail will use your hostname and your default_domain in the ehlo/helo
; smtp greeting. you can manually set the ehlo/helo name if required


so far im user xampp v1.7.7, ive been struggling with this problem for the past 4hours and have been unlucky to find any solutions so I decided to search out the net...

....?? no solution?

Sure there is, see ardav's answer.

Member Avatar for diafol

I usually blast necroposting, but in this case - nice link :)

I have tried setting up the mail server xampp then tested but getting no error and no email being sent either !!! please help. I can post php.ini and sendmail.ini if required.

Do I need to configure my email account?

It is very easy to send email from localhost using PHP Mailer script.

Demo here: PHPMailer Demo
Also refer this article: PHPMailer Reference

I am 100% sure that you will learn "How to use PHP Mailer in Localhost" After reading that article.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.