2013-12-12 46 views
0

我使用SMTP郵件功能得到這個錯誤在CakePHP中無法連接到SMTP服務器。在CakePHP中

的CakePHP代碼:

... 
    try{ 
       $emailClass = new CakeEmail(); 
       $emailClass->config(array(
       'host' => 'ssl://'.$this->smtpHostName, 
       'port' => $this->smtpPort, 
       'username' => $this->smtpUserName, 
       'password' => $this->smtpPassword, 
       'transport' => 'Smtp' 
     )); 
      $emailClass->from(array($this->from => $this->fromName)); 
      $emailClass->to($user_email); 
      $emailClass->subject($subject); 
      $emailClass->emailFormat('html'); 
      $contents = $emailClass->send($message_text); 
      if (!empty($contents)) 
      return true;  
     } 
     catch (Exception $e){ 
       pr($e); 
     } 
... 

錯誤跟蹤:

... 
    [_messageTemplate:protected] => 
    [message:protected] => Unable to connect to SMTP server. 
    [string:Exception:private] => 
    [code:protected] => 500 
    [file:protected] => /opt/lampp/htdocs/site/lib/Cake/Network/Email/SmtpTransport.php 
    [line:protected] => 96 
    [trace:Exception:private] => Array 
... 

驗證了SMTP配置是正確的,因爲我能使用phpmail發送郵件

... 
$headers = array ('From' => $from, 
    'To' => $to, 
    'Subject' => $subject); 
$smtp = Mail::factory('smtp', 
    array ('host' => $host, 
    'auth' => true, 
    'port' => 25, 
    'debug' => true, 
    'username' => $username, 
    'password' => $password)); 

$mail = $smtp->send($to, $headers, $body); 
... 

我不確定它是否與cakephp的配置有關,因爲電子郵件代碼正在另一臺服務器上工作。

嘗試:

fsockopen('ssl://hosthere', porthere); 

SSL問題?

+0

你能告訴我們實際的cakePHP代碼嗎? –

+0

粘貼調試結果($ emailClass); –

+0

再次更新我的問題上面:D –

回答

0

嘗試加入超時後,希望它能解決這個問題!

... 
$headers = array ('From' => $from, 
    'To' => $to, 
    'Subject' => $subject); 
$smtp = Mail::factory('smtp', 
    array ('host' => $host, 
    'auth' => true, 
    'port' => 25, 
    'debug' => true, 
    **'timeout' => 30,** 
    'username' => $username, 
    'password' => $password)); 

$mail = $smtp->send($to, $headers, $body); 
... 
相關問題