Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

amitsolanki24_'s avatar

Email is not sending while running Unit Test

Hey everyone,

Why I'm not getting email during Unit Test. I have checked my mailtrap and also log file but didn't get any mail.

In env.testing file

MAIL_MAILER=log 

In phpunit.xml file

<env name="MAIL_MAILER" value="log"/>

  ✓ send forgot password link success                                                                            0.08s
  ✓ send forgot password link already                                                                            0.08s

and how can create unit test case for reset password verifying link and change after after verifying reset password link API.

0 likes
4 replies
martinbean's avatar

@amitsolanki24_

  1. You’re not going to get emails in Mailtrap if your mail driver is set to log. They’re going to be written to your Laravel log file instead.
  2. You don’t want emails actually being being—even to something like Mailtrap—in tests. That’s what Mail::fake is for.
  3. If you’re trying to test a mail was sent then that’s not a unit test. That’s a feature test. You should be able to run a unit test without booting the Laravel framework, and by extending the PHPUnit base test case only.
2 likes

Please or to participate in this conversation.