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'] = 'example@gmail.com') {
//stop sending emails
$message['send'] = FALSE;
}
}