我正在Drupal 8中使用hook_mail_alter构建一个自定义模块,该模块阻止系统将电子邮件发送到选定的电子邮件地址。 由于某些原因,我当前的模块停止发送任何电子邮件。我需要帮助找出原因。
<?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;
}
}
答案 0 :(得分:0)
这很有趣。检查您的状况:
if($message['to'] = 'example@gmail.com') {
您正在使用赋值运算符,而不是比较。使用双等于(==)
if($message['to'] == 'example@gmail.com') {
您在这里所做的就是分配一些东西,您的情况将永远为真