Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cakephp 2.0 SMTP settings on Email not working

I am using SMTP to send email in my CAKEPHP Project. My email config as follows

class EmailConfig {

    public $Smtp = array(
         'transport' => 'Smtp',
         'from' => array('[email protected]' => 'domainname.com'),
         'host' => 'myhostingserver',
         'port' => 2525,
         'timeout' => 60,
         'username' => '[email protected]',
         'password' => 'secret',
         'client' => null,
         'log' => false
    );

and my Mail Functionality code as follows

    $email    = new CakeEmail('Smtp');
    $result   = $email->template('welcome_mail','default')
                       ->emailFormat('html')
                        ->to($to_email)
                        ->from('[email protected]')
                        ->subject('Welcome to my domain name')
                        ->viewVars($contents);

    if($email ->send('Smtp'))
    {   
        echo ('success');

    }

While i am sending mail its throwing following error SMTP timeout. My SMTP Server details are correct its working fine in an existing server. I don't know where I am wrong

like image 303
AnNaMaLaI Avatar asked Jun 26 '12 08:06

AnNaMaLaI


2 Answers

Check the encryption type (if applicable), e.g. ssl or tls

Your host URL should look something like this in such case

'host' => 'ssl://myhostingserver'

or

'host' => 'tls://myhostingserver'
like image 147
yetanotherse Avatar answered Oct 20 '22 01:10

yetanotherse


If your SMTP server has SSL,you have to enable php_openssl in php.ini to use this service. You can use this code to test

if(!in_array('openssl',get_loaded_extensions())){
    die('you have to enable php_openssl in php.ini to use this service');       
}
like image 28
open source guy Avatar answered Oct 20 '22 00:10

open source guy