Jimothey
Jimothey

Reputation: 2434

CakePHP - can't email via SMTP

pulling my hair out with this one.

When I developed this cakephp (2.2) app on my local machine, I could email via gmail using smtp without a problem. Since then I've deployed it onto a 1and1 server and I can no longer send. What even more frustrating is that I cant seem to get any decent debugging info from cake.

Heres the code:

if($fu['name']) {              

            $url = Router::url('/admin/', true );
            $ms = $url;
            $ms = wordwrap($ms,1000);

           //============Email================//
           // SMTP Options
           $this->Email->smtpOptions = array(
               'port'=>'465',
               'timeout'=>'30',
               'host' => 'ssl://smtp.gmail.com',
               'username'=>'[email protected]',
               'password'=>'password'
                 );
           $this->Email->template = 'newExpenseClaim';
           $this->Email->from    = 'Expense Tracker <[email protected]>';
           $this->Email->to      = '[email protected]'; 
           $this->Email->subject = 'New Expense Claim Submitted - Please Review';
           $this->Email->sendAs = 'both';

           $this->Email->delivery = 'smtp';

           // Set username & url in email
           $this->set('user', $fu['name']);
           $this->set('ms', $ms);
           //$this->Email->send();

           if(!$this->Email->send()) {
                CakeLog::write('debug', $this->Email->smtpError);
            }

           $this->set('smtp_errors', $this->Email->smtpError);

           //============EndEmail=============//   
        }

I get the following debug info each times it fails (printed on screen, nothing goes into the debug log which is massively anoying).

    Connection refused

Error: An Internal Error Has Occurred.
Stack Trace

    CORE/Cake/Network/Email/SmtpTransport.php line 95 → CakeSocket->connect()
    CORE/Cake/Network/Email/SmtpTransport.php line 60 → SmtpTransport->_connect()
    CORE/Cake/Network/Email/CakeEmail.php line 1059 → SmtpTransport->send(CakeEmail)
    CORE/Cake/Controller/Component/EmailComponent.php line 345 → CakeEmail->send(null)
    APP/Controller/ExpenseClaimsController.php line 236 → EmailComponent->send()
    APP/Controller/ExpenseClaimsController.php line 278 → ExpenseClaimsController->notifyAdminsOfNewClaims()
    [internal function] → ExpenseClaimsController->add()
    CORE/Cake/Controller/Controller.php line 485 → ReflectionMethod->invokeArgs(ExpenseClaimsController, array)
    CORE/Cake/Routing/Dispatcher.php line 186 → Controller->invokeAction(CakeRequest)
    CORE/Cake/Routing/Dispatcher.php line 161 → Dispatcher->_invoke(ExpenseClaimsController, CakeRequest, CakeResponse)
    APP/webroot/index.php line 92 → Dispatcher->dispatch(CakeRequest, CakeResponse)

Can anyone help? Thanks in advance

** Updated with wrapper and soctet info **

These are the wrappers and sockets I get returned from those functions:

Wrappers:

array(
    (int) 0 => 'https',
    (int) 1 => 'ftps',
    (int) 2 => 'compress.zlib',
    (int) 3 => 'compress.bzip2',
    (int) 4 => 'php',
    (int) 5 => 'file',
    (int) 6 => 'data',
    (int) 7 => 'http',
    (int) 8 => 'ftp',
    (int) 9 => 'zip'
)

Sockets

array(
    (int) 0 => 'tcp',
    (int) 1 => 'udp',
    (int) 2 => 'unix',
    (int) 3 => 'udg',
    (int) 4 => 'ssl',
    (int) 5 => 'sslv3',
    (int) 6 => 'sslv2',
    (int) 7 => 'tls'
)

Upvotes: 1

Views: 4176

Answers (1)

newman
newman

Reputation: 2719

In first you should check what your hosting support outgoing connection. Simple check is similar

echo implode("", file("http://google.com"));

In second you should check what PHP support SSL connection and it have stream wrapper for SSL. I now not remember how you can check it. But search in google by keywords: PHP stream wrapper SSL

Upvotes: 1

Related Questions