如何在PowerMail回复邮件中插入动态收件人邮箱地址?
解决PowerMail自动回复中显示动态收件人邮箱的方法
方法1:通过后置处理器传递变量
- 编写PHP后置处理器类,在邮件发送前将动态收件人邮箱注入邮件变量:
<?php namespace Vendor\YourExtension\Domain\Service\PostProcessing; use In2code\Powermail\Domain\Model\Form; use In2code\Powermail\Domain\Model\Mail; use In2code\Powermail\Domain\Service\PostProcessing\PostProcessorInterface; class DynamicReceiverProcessor implements PostProcessorInterface { public function process(Form $form, Mail $mail, array $answers, array $settings): void { $receiverEmail = ''; // 遍历表单答案找到动态收件人字段(替换为你的字段标识) foreach ($answers as $answer) { if ($answer->getField()->getMarker() === 'receivers1') { $receiverEmail = $answer->getValue(); break; } } // 将邮箱加入邮件变量 $mail->setVariables(array_merge($mail->getVariables(), ['dynamicReceiver' => $receiverEmail])); } } - 在TypoScript中注册处理器:
plugin.tx_powermail.settings.setup.postProcessing { 10 = Vendor\YourExtension\Domain\Service\PostProcessing\DynamicReceiverProcessor } - 回复邮件模板中直接调用:
您的联系人是:{dynamicReceiver}
方法2:通过TypoScript直接赋值
如果动态收件人存储在页面/内容元素字段中,可直接用TypoScript定义变量:
plugin.tx_powermail.settings.setup.mail.variables { dynamicReceiver = TEXT dynamicReceiver.data = page:tx_powermail_dynamic_receiver // 替换为实际字段路径 }
模板中同样使用{dynamicReceiver}调用。
注意事项
- 优先使用方法1,符合TYPO3扩展开发规范,不会影响PowerMail后续升级;
- 方法2仅适用于动态收件人来自固定字段存储的场景。
内容的提问来源于stack exchange,提问作者user3759978
相关产品推荐
相关产品推荐

