Testing Email Functionality Without Actually Sending Emails

Done a little googling and came across:

Has anyone used it? Is it a reliable tool for testing the email functionality of a PHP site?

I haven’t used that one, but I have used https://mailcatcher.me. That one works nicely.

:disappointed: Looks like it’s no good for me as it needs Ruby. I’m using WAMP on windows

The Symfony framework has some nice email testing functionality including the ability to have all emails sent to one address with enough header information to check if there were correctly created. Not sure how much effort it would to take back fit this to whatever you are using but might be worth a read at least:

You could always use a docker container: https://hub.docker.com/r/schickling/mailcatcher/

I ended up going with this one:

https://nilhcem.github.io/FakeSMTP/index.html

Personally I see no point in testing email functionality without actually sending emails. There are too much possible issues with actual sending that can make your tests unreliable - from the look of the email body to connectivity issues.

Therefore, every time I need to test email sending, I just send them.

Given that I abandoned the mail() function for a long time ago already, and send email using PHPMAiler using my gmail account, there is not a single reason to test without sending.

I can think of two possible scenarios.

To narrow down where in the chain between send and receive the FAIL is occurring.

In a development environment where one doesn’t want to send real emails.

1 Like

That’s what I’ve needed it for

XAMPP provides functionality so that emails get written to a file instead of being sent.

1 Like

I never felt the need for local software replacing SMTP for testing. I simply use debug config options in my php scripts for testing. Most often I use two kinds of them:

  1. A debug flag that causes the emails to be written to a log file instead of sending them. This is good for testing sending bulk emails, scheduled and queued sending via cron. I may also use a delay (sleep) option of about 0.5 seconds so that the duration is more like in real life.

  2. An option for overriding the recipient where all emails are sent to my address. This is good for testing the contents and look of the emails.

I can set these config options both locally and on any production server so I don’t have to worry about having rights to install custom software on some servers.

1 Like

This is not the case. The OP explicitly wants to test the email functionality of a PHP site. It’s hard to test something you don’t use.
Sounds like mutual exclusive statements.

If for example on the game side of the site, player A launches a fleet at player B, depending on player B’s email settings in their profile the game should send out an email to player B informing them that player A launched on them.

By using the program that I’ve gone with I can have the code send the email but the email will just stay on the server only. By it saving the email to a file I can check that the email sends ok and is properly formatted without the emails ever leaving the server.

If it screws up and somehow tries to send 10,000 copies of the same email, them emails will be confined to the server

You can set up an email account that directs to a file and send the emails to that.

I used this several times and recommend it: https://github.com/rnwood/smtp4dev

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.