注册功能使用电子邮件模板布局问题 - cakephp

时间:2011-08-02 08:13:49

标签: cakephp cakephp-1.3

说实话,这是一个奇怪的人。我在本地计算机上完全正常工作,但在生产服务器(CENTOS)上,注册后重定向正在点击电子邮件模板..

我在这里缺少什么?

  function register() {
        $this->layout = 'login';
        $this->set('title_for_layout', 'Register');
        if(!empty($this->data)) {
                  $this->User->create();
                     if($this->User->save($this->data)) {
                        $this->data['User']['group_id'] = 4;
                        $this->_sendNewUserMail( $this->User->id );
                        $this->redirect(array('action' => 'approval'));
                    } else {
                $this->Session->setFlash(__('There were errors found in your registration.  Please check the highlighted fields', true));
                }
        }               
    }

    function _sendNewUserMail($id) {
        $this->Email->smtpOptions = array(
                            'port'=>'25', 
                            'timeout'=>'30',
                            'host' => 'localhost',
                            'username'=>'username',
                            'password'=>'password',
        );
        $this->Email->delivery = 'smtp';
        $User = $this->User->read(null,$id);
        $this->Email->to = array('someone@blah.com');
        $this->Email->subject = 'A new registration has been submitted';
        $this->Email->from = 'Me@blah.com';
        $this->Email->template = 'default';
        $this->Email->sendAs = 'html';
        $this->set('User', $User);
        $this->Email->send();
    }

我完全被这个难过了..

非常感谢您的帮助!

2 个答案:

答案 0 :(得分:1)

我猜想php_openssl没有启用。此外,您应该将smtpOptions和delivery设置移动到_sendNewUserMail

答案 1 :(得分:1)

[来自评论]

生产服务器中似乎有错误(可能是由于SMTP服务器中的配置不同)我假设在生产服务器中您将调试设置为0.因此错误不会显示,这就是为什么它不是重定向,而是呈现电子邮件模板。

您需要调试生产中的smtp错误。为此,您可以添加:

Configure::write('debug', 1);

在发送电子邮件的操作/控制器中,因此您将能够看到错误。此外,您可以检查$this->Email->smtpError变量中的smtp错误。

这样你就能看出什么是错的。我不太了解smtp服务器的配置,所以可能是另一个S.O.问题

希望这有帮助