Sending Email From Localhost

Developers can now test email functionality before deploying to the production or staging server in the local environment itself. We just need to change a few files in XAMPP to make it work.

You need to change two files for it, i.e. php.ini file which you will find "C:\xampp\php\php.ini" and another is sendmail.ini which can be located at "c:\xampp\sendmail\sendmail.ini".

Let's see what you need to change:

  1. php.ini ("C:\xampp\php\php.ini")

    Open file and look for "mail function" in the file and change the below values (here I am using a dummy Gmail account, you need to use actual details).

    SMTP=smtp.gmail.com smtp_port=25 sendmail_from = [email protected] sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t" 

  2. sendmail.ini ("c:\xampp\sendmail\sendmail.ini")

    Open the file and update as below:

    smtp_server=smtp.gmail.com smtp_port=25 [email protected] auth_password=XXXXXXX [email protected] 

Before testing mail() function restart Apache to make it active.

If you are using Gmail you should allow access to less secure apps HERE. The complete Gmail  setting for SMTP is HERE

Note

  1. If It does not work try SMTP port 587 instead 25.
  2. My Current XAMPP version is 1.8.2
  3. My PHP version is 5.4.16