CakePHP - 无法通过SMTP发送电子邮件

时间:2012-11-23 16:20:08

标签: cakephp

用这个把头发拉出来。

当我在本地计算机上开发这个cakephp(2.2)应用程序时,我可以使用smtp通过gmail发送电子邮件而没有任何问题。从那以后我将它部署到1and1服务器上,我再也无法发送了。更令人沮丧的是,我似乎无法从蛋糕中获得任何不错的调试信息。

下面是代码:

if($fu['name']) {              

            $url = Router::url('/admin/', true );
            $ms = $url;
            $ms = wordwrap($ms,1000);

           //============Email================//
           // SMTP Options
           $this->Email->smtpOptions = array(
               'port'=>'465',
               'timeout'=>'30',
               'host' => 'ssl://smtp.gmail.com',
               'username'=>'myemail@gmail.com',
               'password'=>'password'
                 );
           $this->Email->template = 'newExpenseClaim';
           $this->Email->from    = 'Expense Tracker <myemail@email.co.uk>';
           $this->Email->to      = 'myemail@fakeemail.com'; 
           $this->Email->subject = 'New Expense Claim Submitted - Please Review';
           $this->Email->sendAs = 'both';

           $this->Email->delivery = 'smtp';

           // Set username & url in email
           $this->set('user', $fu['name']);
           $this->set('ms', $ms);
           //$this->Email->send();

           if(!$this->Email->send()) {
                CakeLog::write('debug', $this->Email->smtpError);
            }

           $this->set('smtp_errors', $this->Email->smtpError);

           //============EndEmail=============//   
        }

每次失败时我都会得到以下调试信息(在屏幕上打印,没有任何内容进入调试日志,这非常令人讨厌)。

    Connection refused

Error: An Internal Error Has Occurred.
Stack Trace

    CORE/Cake/Network/Email/SmtpTransport.php line 95 → CakeSocket->connect()
    CORE/Cake/Network/Email/SmtpTransport.php line 60 → SmtpTransport->_connect()
    CORE/Cake/Network/Email/CakeEmail.php line 1059 → SmtpTransport->send(CakeEmail)
    CORE/Cake/Controller/Component/EmailComponent.php line 345 → CakeEmail->send(null)
    APP/Controller/ExpenseClaimsController.php line 236 → EmailComponent->send()
    APP/Controller/ExpenseClaimsController.php line 278 → ExpenseClaimsController->notifyAdminsOfNewClaims()
    [internal function] → ExpenseClaimsController->add()
    CORE/Cake/Controller/Controller.php line 485 → ReflectionMethod->invokeArgs(ExpenseClaimsController, array)
    CORE/Cake/Routing/Dispatcher.php line 186 → Controller->invokeAction(CakeRequest)
    CORE/Cake/Routing/Dispatcher.php line 161 → Dispatcher->_invoke(ExpenseClaimsController, CakeRequest, CakeResponse)
    APP/webroot/index.php line 92 → Dispatcher->dispatch(CakeRequest, CakeResponse)

有人可以帮忙吗?提前致谢

**更新了包装器和soctet信息**

这些是我从这些函数返回的包装器和套接字:

包装器:

array(
    (int) 0 => 'https',
    (int) 1 => 'ftps',
    (int) 2 => 'compress.zlib',
    (int) 3 => 'compress.bzip2',
    (int) 4 => 'php',
    (int) 5 => 'file',
    (int) 6 => 'data',
    (int) 7 => 'http',
    (int) 8 => 'ftp',
    (int) 9 => 'zip'
)

套接字

array(
    (int) 0 => 'tcp',
    (int) 1 => 'udp',
    (int) 2 => 'unix',
    (int) 3 => 'udg',
    (int) 4 => 'ssl',
    (int) 5 => 'sslv3',
    (int) 6 => 'sslv2',
    (int) 7 => 'tls'
)

1 个答案:

答案 0 :(得分:1)

首先,您应该检查您的托管支持传出连接。简单检查类似

echo implode("", file("http://google.com"));

第二,您应该检查哪些PHP支持SSL连接,并且它具有SSL的流包装器。 我现在不记得你怎么检查了。但是通过关键字在谷歌搜索:PHP流包装器SSL