I am able to block emails successfully, but whenever an email is blocked Drupal displays an error message that says "Unable to send e-mail. Please contact the site admin, if the problem persists."
I believe this is because you are setting $message['to'] to NULL on line 129 (hook_mail_alter). While this method does block the email, it seems to basically confuse Drupal into thinking something went wrong.
I have tried blocking emails with custom code in the past (using the NULL method that you use, as well as others), but I never found a way to do so without that error message showing up. One solution could be to manually remove the error message, described in this post.
Regardless of how you plan to prevent it, I do think that the error message should not show up.
Comments
Comment #1
john.karahalis commentedTypo correction: "I do not think that the error message should show up."
Comment #2
Anonymous (not verified) commentedThank you John.
I've added the following code to the 6.x-1.x module. But I'm unable to test it with my current setup. Can someone please test this code. Just insert it after $message['to'] = NULL;
Comment #3
truyenle commentedNo, it is still there since the error doesn't generate immediately after assigning $message['to'] = NULL but when drupal system send email. So clear error message here doesn't really supress the message.
My other simple solution is to assign it to a fake non-exist email address like
$message['to'] = "drupal-fake-email@drupal.org";
It works for me.