0
votes

I am building a custom module using hook_mail_alter in Drupal 8 which stops the system from sending emails to a selected email address. My current module stops sending any emails for some reasons. I need help to figure out why.

<?php
use Drupal\Core\Mail\MailManagerInterface;

/**
* Implements hook_mail_alter
*/

function terminate_emails_mail_alter(&$message) {

    //filter by email address, which is not working
    if($message['to'] = '[email protected]') {

    //stop sending emails
      $message['send'] = FALSE;    
    }
}
1

1 Answers

0
votes

This is funny. Check your if condition:

if($message['to'] = '[email protected]') {

You are using assignment operator, not comparison. Use double equal-to (==)

if($message['to'] == '[email protected]') {

What you are doing here, is assign something, and your condition will always be true