Support the ongoing development of Laravel.io →
posted 5 years ago
Last updated 5 months ago.
0

What is Mail returning in that IF statement?

0

Hey, @GhostMech thanks for your reply, I found a solution online.

Mail::send()

Method does not return anything so in my case when I'm using it inside the if () statement it never returns anything true so by default it returns false. That's why I am getting the else () statement returned.

So in order to get something like this to work, you would have to use an if() statement like this

$post = (object) $_POST;
Mail::to($post->email)->send(new OrderReceived($post));

if (count(Mail::failures() < 0)) {
    echo "Thank you mail sent";
} else {
    echo "There was an error";
}
Mail::failures

Returns an array of failed recipients

Just in case anyone else runs into this problem.

Last updated 5 years ago.
0

Cool. Thanks for sharing. I always inspect what my IF statements return. Some PHP functions don't always return boolean, so you have to evaluate with something like if ($var === true), or something like that.

Glad you got it solved.

0

Sign in to participate in this thread!

LaraJobs

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.