Cakephp 2.0 Email SMTP Settings Not Working

I use SMTP to send email in a CAKEPHP project. Email configuration as follows

class EmailConfig {

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

and the code of my mail function as follows

    $email    = new CakeEmail('Smtp');
    $result   = $email->template('welcome_mail','default')
                       ->emailFormat('html')
                        ->to($to_email)
                        ->from('contact@mydomainname.com')
                        ->subject('Welcome to my domain name')
                        ->viewVars($contents);

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

    }

While I am sending mail, it throws the following SMTP timeout error . Information about my SMTP server works correctly on an existing server. I do not know where I am wrong.

+5
source share
3 answers

Check the type of encryption (if applicable), for example. ssl or tls

In this case, your host url should look something like this:

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

or

'host' => 'tls://myhostingserver'
+6
source

SMTP- SSL, php_openssl php.ini .

if(!in_array('openssl',get_loaded_extensions())){
    die('you have to enable php_openssl in php.ini to use this service');       
}
+1

In addition to what has already been said here, the module must be loaded. I found that some ports are blocked on some servers. I used this script to test some servers:

<?php

if(!in_array('openssl',get_loaded_extensions())){
    die('you have to enable php_openssl in php.ini to use this service');       
} else {
    echo "php_openssl in php.ini is enabled <br />";
}

// fill out here the smpt server that you want to use
$host = 'ssl://smtp.gmail.com';
// add here the port that you use for for the smpt server
$ports = array(80, 465);

foreach ($ports as $port)
{
    $connection = @fsockopen($host, $port);
    if (is_resource($connection))
    {
        echo $host . ':' . $port . ' ' . '(' . getservbyport($port, 'tcp') . ') is open.<br />' . "\n";
        fclose($connection);
    } else {
        echo $host . ':' . $port . ' is not responding.<br />' . "\n";
    }
}

?>
0
source

All Articles