Recently I have been developing a multisite network on a localhost installation. I am currently in the beginning stages of a site build, and currently building up the dashboard and including some functionality. One feature of the site is to allow users to create and maintain there own personal blogs. I needed to test out the creation of accounts and other sites on the network. I wanted to receive emails every time this happened, to replicate a real world production environment the best I could. I also wanted to be able to reset passwords without having to log-in to phpmyadmin every time.
I did a whole lot of research into the topic, and came across many articles all claiming that the process was extremely easy to set up. It took me two days to resolve the issue, not to mention a whole lot of reading and de-bugging. I was finally able to resolve the issue to enable emails sent from localhost. That includes emails from gravity forms, emails for password resets and update notifications.
To start make sure that you have XAMPP installed and an installation of WordPress running. If your not sure how to set up XAMPP , check back at one of my previous articles and follow the steps provided (Using XAMPP for local development).
We will be editing two separate files within the XAMPP directory to enable email being sent from localhost. The two files we will need to edit are PHP.ini and Sendmail.ini.
PHP.ini
After you have XAMPP installed, go to the root directory for the installation. If you installed it on your C:\ drive than it would be C:\XAMPP. I have mine installed to a flash drive, so mine sits on S:\Server Files\XAMPP. Once in the XAMPP root direct yourself to the PHP folder (\XAMPP\PHP). From here you can open up the PHP.ini file in your favorite text editor (I use notepad++).
Once you have the PHP.ini file opened, scroll down to line 1146 and comment out the entire line (you can comment out the line by placing a semi-colon (;) at the beginning of the line). After you have commented out line 1146, scroll up to line 1143, and un-comment that line (remove the semi-colon).
For reference this is how your PHP.ini file, line 1140-1154 should appear:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
; XAMPP IMPORTANT NOTE (1): If XAMPP is installed in a base directory with spaces (e.g. c:\program filesS:\Server Files\XAMPP) fakemail and mailtodisk do not work correctly. ; XAMPP IMPORTANT NOTE (2): In this case please copy the sendmail or mailtodisk folder in your root folder (e.g. C:\sendmail) and use this for sendmail_path. ; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder) sendmail_path = "\"S:\Server Files\XAMPP\sendmail\sendmail.exe\" -t" ; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the S:\Server Files\XAMPP\mailoutput folder ;sendmail_path="\"S:\Server Files\XAMPP\mailtodisk\mailtodisk.exe" -t" ; Force the addition of the specified parameters to be passed as extra parameters ; to the sendmail binary. These parameters will always replace the value of ; the 5th parameter to mail(), even in safe mode. ;mail.force_extra_parameters = ; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename mail.add_x_header=Off |
Now what we did above was tell XAMPP where the sendmail.exe file is located.
And that’s it for your PHP.ini file!
Sendmail.ini
Now lets move on to your sendmail.ini file (which is much shorter). Your Sendmail.ini file can be found inside of the sendmail directory in the XAMPP root (\XAMPP\Sendmail\Sendmail.ini). Again open the file inside of your favorite text editor.
- *Tip*: I would recommend making a backup of the file inside of the same folder and just appending a ‘2’ to the end of the file name, just in case something goes wrong down the road.
Now you can copy the provided code below and replace the contents of Sendmail.ini file with it.
1 2 3 4 5 6 7 8 9 10 |
[sendmail] smtp_server=smtp.gmail.com smtp_port=587 smtp_ssl=auto error_logfile=error.log debug_logfile=debug.log auth_username=gmail-account@gmail.com auth_password=gmail-password force_sender=gmail-account@gmail.com |
Don’t forget to swap out your credentials!
gmail-account@nullgmail.com : Your Gmail username
gmail-password : Your Gmail password
That’s it, your XAMPP is all set up to start sending emails!
Restart
Now just restart your Apache and MySQL modules in XAMPP, and go ahead and test out the newly enabled email functionality. It’s actually quite simple to set this up, but requires a little bit of knowledge of the XAMPP file structure and SMTP settings.
Hopefully someone finds this useful and I save someone a headache or some development time as I struggled for a few days with this issue. Thanks for reading!
Did this help you, or are you still having issues? Let me know in the comments and I’ll do my best to help!