Search code examples
phpcakephpsmtpgmailcakephp-2.0

CakePHP 2.0 Email SMTP Error


I'm getting this error when I try to mail from CakePHP 2.0 using CakeEmail:

SMTP Error: 502 5.5.1 Unrecognized command. p1si477061pbk.249

I'm sending from Gmail, and here is my config:

public $gmail = array(
    'transport' => 'Smtp',
    'host' => 'aspmx.l.google.com',
    'port' => 25,
    'timeout' => 30,
    'username' => 'user',
    'password' => 'secret',
    'client' => null,
    'log' => true
    //'charset' => 'utf-8',
    //'headerCharset' => 'utf-8',
);

The host and port came from this article here: http://www.google.com/support/a/bin/answer.py?answer=176600


Solution

  • You have to use SSL option in your code.

    /* SMTP Options */
    $this->Email->smtpOptions = array(
    'port'=>'465',
    'timeout'=>'30',
    'host' => 'ssl://smtp.gmail.com',
    'username'=>'[email protected]',
    'password'=>'your_gmail_password',
    );
    
    /* Set delivery method */
    $this->Email->delivery = 'smtp';