-1

In classic way, a registered or activated user will necessarily always have an email. In my specific context we have to deal with few users with no email address. The activation relies on many fields already in database, and email is not necessarily needed.

In this context, anyway we have to send notifications campaign to users to send them informations. I deal with the fail function to retrieves failed notifications and list them on an interface.

The problem I'm facing is with users without any email. I was expecting that sending a notification to a user without any email address would fail but it's not the case. I need to be able to add those users to the failed notifications list...

The notification just goes its way with no fail.

Am I missing something here?

BenDev
  • 349
  • 3
  • 18
  • You will need to provice way more details. Sending a notification does NOT imply sending an email. You should also show your code and configuration. – Frnak May 18 '21 at 08:09

1 Answers1

0

Sorry, I should have been more specific:

The notification use a notification class that sends notification via mail and database with queuing. Each notification is recorded in database and has a state into its 'data' field set to 'OK' when it goes well or 'FAILED' when it fails.

I've solved the problem by managing throw the loop: if the user has no email then the notification mail is not sent and the notification is created manually into the database with the 'FAILED' flag via a custom method 'force_mark_notification_as_failed'.

foreach ($users as $user) {
    if ($user->email != '') {
        $when = $when->addSeconds(1);
        $user->notify((new MailNotificationManager($campaign_id, $users_amount, 'releve_notes', $user->email))->delay($when));
    } else {
        $this->force_mark_notification_as_failed($campaign_id, $users_amount, $user->id);
    }
}
BenDev
  • 349
  • 3
  • 18