0

当用户注册时,我正在尝试向我的网站管理员发送第二封电子邮件。

我制作了一个发送电子邮件的 postHook 片段,但它没有工作 - 注册过程按预期工作,但我没有收到来自钩子的第二封电子邮件。

在测试中,我将钩子从 postHook 设置为 preHook 并再次尝试 - 这次表单根本没有处理 - 没有创建新用户,也没有发送激活电子邮件。它甚至没有重定向到提交的ResourceId。

因此,我删除了 preHook Snippet 中的所有内容,除了return true;并再次尝试 - 仍然没有。

看来登录根本不会运行任何钩子。我不知道为什么。

任何人都可以提出任何修复建议吗?

我的注册片段是:

[[!Register?
    &submitVar=`registerbtn`
    &activationResourceId=`19`
    &activationEmailTpl=`lgnActivateEmailTpl`
    &activationEmailSubject=`Thanks for Registering!`
    &submittedResourceId=`23`
    &usergroups=`2`
    &validate=`nospam:blank,
    username:required:minLength=^6^,
    password:required:minLength=^6^,
    password_confirm:password_confirm=^password^,
    fullname:required,
    email:required:email`
    &preHooks=`adminEmailHook`
]]
4

1 回答 1

1

我以前做过类似的事情。有我的代码:

[[!Register? &postHooks=`sendMessageToAdmin`

片段 sendMessageToAdmin:

 <?php
    $message = 'Auto message:<br><br>A new user signed up: '.$hook->getValue('fullname') . ', using email address '.$hook->getValue('email').'.';

    $modx->getService('mail', 'mail.modPHPMailer');
    $modx->mail->set(modMail::MAIL_BODY,$message);
    $modx->mail->set(modMail::MAIL_FROM,'info@domain.com');
    $modx->mail->set(modMail::MAIL_FROM_NAME,'My website');
    $modx->mail->set(modMail::MAIL_SENDER,'Auto message from my website');
    $modx->mail->set(modMail::MAIL_SUBJECT,'Someone signed up');
    $modx->mail->address('to','info@domain.com');
    $modx->mail->setHTML(true);
    if (!$modx->mail->send()) {
        $modx->log(modX::LOG_LEVEL_ERROR,'sendMessageToAdmin: An error occurred while trying to send the email: '.$err);
    }
    $modx->mail->reset();
    /* tell our snippet we're good and can continue */
    return true;
于 2015-03-27T15:14:01.343 回答