cakePHP-电子邮件客户端:在localhost上读取gmail收件箱

时间:2014-02-07 09:50:44

标签: php email cakephp cakephp-2.3 email-client

我目前正在做一个项目,但我仍在使用本地计算机。问题是我似乎无法使用此连接gmail邮箱 plugin

真正的问题是,我不知道使用插件在localhost上连接gmail帐户的代码。我在配置中有这个:

public $emailTicket = array(
        'datasource' => 'ImapSource',
        'server' => 'localhost',
        'connect' => 'imap/tls/novalidate-cert',
        'username' => '************@gmail.com',
        'password' => '*********',
        'port' => '143', //incoming port 
        'ssl' => false,
        'encoding' => 'UTF-8',
        'error_handler' => 'php',
        'auto_mark_as' => array(
        'Seen',
        // 'Answered',
        // 'Flagged',
        // 'Deleted',
        // 'Draft',
        ),
    );

然后cake返回错误:Error: Unable to get imap_thread after 4 retries. 'Can't connect to **localhostName**,143: Refused

任何人都知道正确的方法吗?或者如果有可能我继续在本地机器上工作,如果是这样,怎么样?

[编辑]

在插件代码中,这是为php的imap_open()准备参数的方法:

case 'imap':
                $this->_connectionString = sprintf(
                    '{%s:%s%s%s}',
                    $this->config['server'],
                    $this->config['port'],
                    @$this->config['ssl'] ? '/ssl' : '',
                    @$this->config['connect'] ? '/' . @$this->config['connect'] : ''
                );
                break;

$retries = 0;
            while (($retries++) < $this->config['retry'] && !$this->thread) {
                $this->Stream = imap_open($this->_connectionString, $this->config['username'], $this->config['password']);
                $this->thread = @imap_thread($this->Stream);
            }

2 个答案:

答案 0 :(得分:1)

您需要使用Gmail传入电子邮件imap服务器设置:

public $emailTicket = array(
        'datasource' => 'ImapSource',
        'server' => 'imap.gmail.com',
        'connect' => 'imap/tls/novalidate-cert',
        'username' => '************@gmail.com',
        'password' => '*********',
        'port' => '993', //incoming port 
        'ssl' => true,
        'encoding' => 'UTF-8',
        'error_handler' => 'php',
        'auto_mark_as' => array(
        'Seen',
        // 'Answered',
        // 'Flagged',
        // 'Deleted',
        // 'Draft',
        ),
    );

并且当然在你的Gmail帐户上启用了imap ...

答案 1 :(得分:-1)

class EmailConfig {
    public $gmail = array(
        'host' => 'ssl://smtp.gmail.com',
        'port' => 465,
        'username' => 'my@gmail.com',
        'password' => 'secret',
        'transport' => 'Smtp'
    );
}

用于控制器操作

App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('gmail');

帮助链接
http://book.cakephp.org/2.0/en/core-utility-libraries/email.html http://www.shahariaazam.com/send-email-from-localhost-in-cakephp-using-cakeemail/#