php - Unable to connect to SMTP server. in CakePHP
I got this error in cakephp using the smtp mail function
cakephp code:
...
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);
}
...
error trace:
...
[_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
...
Verified that the smtp configuration is correct because I was able to send an email using 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);
...
I'm not sure if it has something to do with cakephp's config because the email code is working on another server.
tried:
fsockopen('ssl://hosthere', porthere);
ssl problem?
Answer
Solution:
Try after adding timeout, Hope it will solve this problem!