我正在编写一个插件,它应该在发送给最终用户的电子邮件中添加一个(动态)附件。但我被困在一件事上。
首先,我使用EMAIL_ON_SEND
钩子向电子邮件添加附件。但似乎每次调用它都会在每封电子邮件中添加一个附件。
对于每封电子邮件,它会被调用两次。因此,对于第一封邮件,它将添加 2 个附件,第二封邮件将添加 4 个,依此类推。
第二种方法是使用ON_SENT_EMAIL_TO_USER
钩子。但是在发送电子邮件(在一个段中)之前似乎没有调用这个。
class EmailSubscriber extends CommonSubscriber
{
protected $helper;
public function __construct(IntegrationHelper $helper)
{
$this->helper = $helper;
$this->parser = new ApiParser();
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
// EmailEvents::EMAIL_ON_SEND => ['onEmailSend', 100],
EmailEvents::ON_SENT_EMAIL_TO_USER => ['onEmailSend', 100],
];
}
/**
* Search and replace tokens with content
*
* @param EmailSendEvent $event
*/
public function onEmailSend(EmailSendEvent $event)
{
error_log('123');
}
不知何故,我必须挂钩发送电子邮件而不是事件(?)的实际操作。但我不知道是哪一个