[Tutorial] How to add MailHog to Laragon and make it autorun using Procfile
-
Here's how:
- Download MailHog:
https://github.com/mailhog/MailHog/releases/download/v1.0.0/MailHog_windows_amd64.exe - Move it to `C:\laragon\usr\bin\MailHog.exe
- Open Laragon's Procfile (Menu > Laragon > Procfile) and add these lines:
MailHog: MailHog.exe autorun MailHog Admin: http://localhost:8025 autorun
That's all. I hope you enjoyed yourself
- Download MailHog:
-
1 liner (using Menu > Laragon > Terminal):
cd %LARAGON_ROOT%\usr & curl -L https://github.com/mailhog/MailHog/releases/download/v1.0.0/MailHog_windows_amd64.exe > bin\MailHog.exe & echo MailHog: MailHog.exe autorun >> Procfile & echo MailHog Admin: http://localhost:8025 autorun >> Procfile
-
Thank you. I opened URL and it is working.
Just to find out how to connect it with Laragon (PHP) PHPMailer function.
Sent few messages via contact forms on different websites and Inbox still shows (0).
-
@Stagger-Lee
MailHog will act as a local smtp server, so when you create the smtp connection with PHPMailer, you need to give it the following settings:MAIL_DRIVER=smtp MAIL_HOST=127.0.0.1 MAIL_PORT=1025 MAIL_USERNAME=testuser MAIL_PASSWORD=testpwd
Ports can change depending on the config you set up MailHog with. It's also possible that it won't require any authentication... depends on the use case.
-
Thank you @blackfyre. Lost some time because of overflow of options for WordPress code. Now it is OK.
Here it is a few lines plugin for WordPress. Just install it as any plugin. Or take action hook out and use in custom functions.php. Maybe better to install as a plugin. Later can be deleted. Less risk later will remain on production site and ruin mail sending.
-
Is there any way to make saving mails persistent ? Some other GPL script for collecting localhost mails ? Some other solution.
It would help a lot by tweaking newsletters, and all possible HTML format mails, contact forms. As it is now not very useful. Restart Laragon and mails are gone.
-
@Stagger-Lee Mailhog isn't ment to be persistent in any way. If you want persistence, I suggest you try mailtrap.io for that.
But I cannot imagine why would anyone want persistence for local email development... I've been doing it for years and I'm happy to see them go away at the end of the day...
-
@Stagger-Lee said in [Tutorial] How to add MailHog to Laragon and make it autorun using Procfile:
Thank you @blackfyre. Lost some time because of overflow of options for WordPress code. Now it is OK.
Here it is a few lines plugin for WordPress. Just install it as any plugin. Or take action hook out and use in custom functions.php. Maybe better to install as a plugin. Later can be deleted. Less risk later will remain on production site and ruin mail sending.
Hi,can you please re-upload? When I click on the link it says "Not Found". Thanks
-
@KoolPal said in [Tutorial] How to add MailHog to Laragon and make it autorun using Procfile:
Hi,can you please re-upload? When I click on the link it says "Not Found". Thanks
Will do it tonight. Sitting now on notebook without servers.
-
Here it is.
-
Sorry. Cannot download. Can you paste the code here instead?
-
@KoolPal: Sorry - it's the forum's issue. I've fixed it.
-
@leokhoa Not sure if @Stagger-Lee needs to re-upload the file again. I still get "not found" when I click the older links above.
-
@leokhoa
http://localhost:8025 does not open. What step am I missing?
-
@KoolPal : Can you show me your Procfile?
-
Okay, this is how I managed to make Mailhog work with Laragon. I would love it if anyone could share an easier way
- Download MailHog:
https://github.com/mailhog/MailHog/releases/download/v1.0.0/MailHog_windows_amd64.exe - Rename it to MailHog.exe
- Move it to `C:\laragon\usr\bin\MailHog.exe
Open Laragon's Procfile (Menu > Laragon > Procfile) and add these lines:
MailHog: MailHog.exe autorun
MailHog Admin: http://localhost:8025 autorun - Open F:\laragon\bin\php\php-7.1.14-Win32-VC14-x64\php.ini
Changes:
SMTP = localhost
smtp_port = 1025
sendmail_path="F:\laragon\usr\bin\MailHog.exe sendmail" - Laragon settings, turn OFF Mail Catcher
- Restart Laragon
- Install Mailhog for WordPress plugin. Deactivate any SMTP plugin that may be installed like Post SMTP, etc.
- Run "F:\laragon\usr\bin\MailHog.exe" and keep this open for the emails to be captured.
- Launch http://localhost:8025/ which will only work when 8 is running.
Is there a simpler way to make Mailhog run with Laragon?
- Download MailHog:
-
# Format: ; Program Name: autorun COMMANDS env_file=PATH_OF_FILE pwd=PATH_OF_WORKING_DIR ENV_VAR1=VALUE ENV_VAR2="VALUE WITH SPACE" # Help: ; Program Name: Will be displayed on Procfile or Tools' Menu (can contains space) ; autorun: Your COMMANDS will be run automatically when Laragon starts ; COMMANDS: A command or a series of commands (separated by & ) ; env_file: You can set environment variables directly or put them to the file ; PWD: Current working directory - where the COMMANDS run # Examples: ; My Cool App: autorun node start $PORT PORT=9000 env_file=usr\my_file.env PWD=usr/proj/myapp DB_HOST=1.2.3.4 DB_PORT=9999 DB_USER=user DB_PASS="!$Ab.cs3cre1" DB_NAME=cooldb ; Awesome Tool: "PATH HAS SPACES SHOULD BE QUOTED LIKE THIS" ------------------------------------------------------------------------------ MailHog: MailHog.exe autorun MailHog Admin: http://localhost:8025 autorun
-
@KoolPal : The Procfile looks good.
It helps 8.) is autorun when you start Laragon.There should be 2 entries in:
- Menu > Laragon > MailHog
- Menu > Laragon > MailHog Admin
What do you see when clicking Menu > Laragon > MailHog?
-
@leokhoa I see TWO options:
Clicking on the Mailhog - Autorun does nothing
Clicking on Mailhog Admin - Autorun launches a new window at http://localhost:8025/Is this how it is supposed to work?
-
The resources shared in this thread are fantastic. I'm able to have MailHog up and running in my local development environment exactly as I'd expect. However, there's one little thing that's bugging me...
I want ALL email coming from PHP to go through MailHog. So, I've edited my php.ini file as @KoolPal has documented. MailHog works as expected when I reload Apache with the updated php.ini config. However, if I exit Laragon and start it back up again, the
sendmail_path
value is overwritten to Laragon's default sendmail config - meaning I need to go in and update it to use MailHog and reload Apache - every time I start Laragon.How can I prevent Laragon from overwriting the
sendmail_path
value on startup?Thanks,
pixelbrad