【问题标题】:how to trouble shoot CakePHP email component errors in Sign Me Up plugin如何解决 Sign Me Up 插件中的 CakePHP 电子邮件组件错误
【发布时间】:2024-03-09 04:00:02
【问题描述】:

我正在使用来自 Jotlab 的 Sign Me Up 插件,但在发送电子邮件时遇到问题。我试图联系作者,但到目前为止没有运气。

我将它与 ACL 插件一起使用,到目前为止,除了发送电子邮件之外的所有功能都可以正常工作。所有的研究和故障排除都没有得到任何答案。

这是一个 cakephp 2.x 版本,我知道电子邮件组件已被弃用但应该可以工作。

当我提交注册表时,记录确实被插入,但电子邮件没有发送,我收到此错误消息。

#0 C:\wamp\www\blue2\lib\Cake\Network\Email\CakeEmail.php(967): MailTransport->send(Object(CakeEmail))
#1 C:\wamp\www\blue2\lib\Cake\Controller\Component\EmailComponent.php(345): CakeEmail->send(Array)
#2 C:\wamp\www\blue2\app\Plugin\sign_me_up\Controller\Component\SignMeUpComponent.php(143): EmailComponent->send(Array)
#3 C:\wamp\www\blue2\app\Plugin\sign_me_up\Controller\Component\SignMeUpComponent.php(103): SignMeUpComponent->__sendActivationEmail(Array)
#4 C:\wamp\www\blue2\app\Plugin\AclManagement\Controller\UsersController.php(57): SignMeUpComponent->register()
#5 [internal function]: UsersController->register()
#6 C:\wamp\www\blue2\lib\Cake\Controller\Controller.php(473): ReflectionMethod->invokeArgs(Object(UsersController), Array)
#7 C:\wamp\www\blue2\lib\Cake\Routing\Dispatcher.php(104): Controller->invokeAction(Object(CakeRequest))
#8 C:\wamp\www\blue2\lib\Cake\Routing\Dispatcher.php(86): Dispatcher->_invoke(Object(UsersController), Object(CakeRequest), Object(CakeResponse))
#9 C:\wamp\www\blue2\app\webroot\index.php(96): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#10 {main}

这是控制器中用于注册功能的代码:

public function register() {
    $this->__isLoggedIn();
    if (!empty($this->data)) {
        extract($this->settings);
        $model = $this->controller->modelClass;
        $this->controller->loadModel($model);
        $this->controller->{$model}->set($this->data);

        if (CakePlugin::loaded('Mongodb')) {
            $this->controller->{$model}->Behaviors->attach('Mongodb.SqlCompatible');
        }

        if ($this->controller->{$model}->validates()) {
            if (!empty($activation_field)) {
                $this->data[$model][$activation_field] = $this->controller->{$model}->generateActivationCode($this->data);
            } elseif (!empty($useractive_field)) {
                $this->data[$model][$useractive_field] = true;
            }

            if ($this->controller->{$model}->save($this->data, false)) {
                //If an activation field is supplied send out an email
                if (!empty($activation_field)) {
                    $this->__sendActivationEmail($this->data[$model]);
                    if (!$this->controller->request->is('ajax')) {
                        $this->controller->redirect(array('action' => 'activate'));
                    } else {
                        return true;
                    }
                } else {
                    $this->__sendWelcomeEmail($this->data[$model]);
                }
                if (!$this->controller->request->is('ajax')) {
                    $this->controller->redirect($this->Auth->loginAction);
                } else {
                    return true;
                }
            }
        }
    }
}

“发送激活邮件”和“发送欢迎邮件”如下:

protected function __sendActivationEmail($userData) {
    $this->__setUpEmailParams($userData);
    $this->__parseEmailSubject('activation', $userData);
    if ($this->__setTemplate(Configure::read('SignMeUp.activation_template'))) {
        if ($this->Email->send($userData)) {
            return true;
        }
    }
}

protected function __sendWelcomeEmail($userData) {
    $this->__setUpEmailParams($userData);
    $this->__parseEmailSubject('welcome', $userData);
    if ($this->__setTemplate(Configure::read('SignMeUp.welcome_template'))) {
        if ($this->Email->send($userData)) {
            return true;
        }
    }
}

我已阅读电子邮件中的蛋糕文档,并尝试了很多方法,包括多次重新安装。

非常感谢任何有关如何解决这些错误消息的帮助。

谢谢,保罗

【问题讨论】:

    标签: email cakephp components


    【解决方案1】:

    已找到丢失的文件。由于某种原因,我在 view/emails/text 中的“default.ctp”文件丢失了。还要确保其中包含以下代码:

    <?php echo $content; ?>
    

    电子邮件现在可以正常工作了。

    【讨论】: