I have limited space and don't want to deal with Apache-MySQL-PHP; I don't need the security nor the extra functionality. PHP has its own simple webserver now! I only need to test, on Windows, web forms for a website to be uploaded to a commercial host running Linux. Not everyone is developing an in-house mail application.
I thought pointing smtp dir to "fake sendmail" meant to use a directory as a "black hole", which is not the case, of course!You need either a) a "sendmail" or alternative program installed locally, or b) on Windows, an MTA (mail transfer agent) connecting to a real server where you have an account.
*Most* simple programs ("fake sendmail", "fake sendmail with TLS" + one more) weren't maintained for *years* and don't work. ("SmtpStub" says it's listening and so does my firewall, which is always a high random one, even though 25 is its default config, or I change it. However, PHP warning says no one's listening.)
I tried "MailHog" *last* because online tutorials configure it with blogs + imply "mhsendmail" is required. Turns out this *is a simple program usable by itself*! It's a *no-install Windows executable* that stores mail in memory or to disk, and has a GUI web interface to view, read + delete email live or from disk. Its CLI options *work*, including changing the port! (By default, it listens on 1025 for email and 8025 for HTTP requests by which it serves the webmail GUI.)
Using this with PHP's "mail()" function is easy as pie:
1) Download and save MailHog wherever you want, preferably a short path.
2) Create a folder for mail storage if you want to store mail.
3) I use MailHog default ports, but tested others worked via options. Edit your "php.ini" (MailHog automatically uses "user@example.com" for "to", so you don't need to configure in PHP):
SMTP = localhost
smtp_port = 1025
sendmail_from = test@example.com
4) Start PHP with its own webserver, with all requests interpreted relative to your website directory (using *forward slashes*), per the manual:
php -S localhost:8000 D:/sites/MySite
5) Change to the directory where you saved MailHog:
D:\SomeDir
6) Start MailHog (assume you saved the executable as "mailhog.exe") with options to bind to localhost, save mails to MAIL folder :
start mailhog -hostname localhost -storage maildir -maildir-path D:\MAIL
PHP will run in the current CLI, MailHog opens its own CLI. Now you can browse your site with "localhost:8000" or directly to your form like "localhost:8000/mail.html". Fill out a mail and send it. Use "localhost:8025" for the webmail (let JavaScript run on localhost); read and delete as desired. If *not* storing to disk, emails in memory are lost when you stop MailHog's server (close its CLI or press "Ctrl+C"). Stop PHP's webserver with "Ctrl+C" "y" 'Enter'.
If you save your binaries with version info, etc, just make a *shortcut* with *NO* ".ink" extension, named "mailhog", which can be run the same way. Better, you can open its Properties and put options in the "Target" box. (If you must quote the path to the executable because it has spaces, do *NOT* make options part of the quote, put them outside after a space!)
If all goes well, create a Windows batch script to run things and put your options there (or keep them in the shortcut, assuming you use it). You could even stick batch scripts in each site directory with different settings and servers.
My "runservers.bat" changes to the directory where MailHog is, starts MailHog via the shortcut (which has options), and starts PHP's web server:
cd /d D:\SomeDir
start mailhog
php -S localhost:8000 -t D:/sites/MySite
I can run this script (stored in D:) like:
cd /d D:
runservers.bat
NOTE, use "-storage memory" and *no* -maildir-path if you *don't* want mail saved to disk (these settings are *defaults* anyway):
start maildir -hostname localhost -storage memory
NOTE, to start PHP with links relative to current directory instead of specifying, "cd" to it and *don't* use -t D:/sites/MySite:
php -S localhost:8000
*THE MOST SIMPLE USAGE*
start maildir
php -S localhost:8000