簡體   English   中英

無法連接到SMTP服務器。 在CakePHP中

[英]Unable to connect to SMTP server. in 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問題?

添加超時后嘗試,希望它將解決此問題!

...
$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);
...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM