2014-02-07 38 views
0

我目前正在做一个项目,但我仍然在本地机器上工作。问题是,我似乎无法使用此 plugincakePHP-电子邮件客户端:读本地主机上的Gmail邮箱

真正的问题是,我不知道使用插件在本地主机上使用Gmail帐户连接代码中的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', 
     ), 
    ); 

然后蛋糕会返回一个错误: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); 
      } 
+0

事情是[此链接](http://stackoverflow.com/questions/712392/send-email-using -gmail的SMTP服务器从 - PHP页面)? – loveNoHate

+0

@dollarvar嗨,先生,不,我正在尝试使用php的imap(或者插件make使用php的[imap_open](http://www.php.net/imap_open))来阅读电子邮件。这个想法是在应用程序 – LogixMaster

+0

内创建一个迷你电子邮件客户端。好吧,我试图谷歌,但我想你需要一个'IP'或某个地址从谷歌邮件而不是本地主机? – loveNoHate

回答

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', 
     ), 
    ); 

而且ofcourse启用Gmail帐户的IMAP ...

+0

谢谢你回答!我已经试过这个,并且返回: '错误:4次重试后无法获得imap_thread。 '[CLOSED] IMAP连接断开(服务器响应)''为什么会发生这种情况的任何想法? – LogixMaster

+1

@ user2678538你在你的Gmail帐户上启用了IMAP吗?尝试调试插件,并看看:http://www.php.net/manual/en/function.imap-open.php –

+0

是的,我确实在谷歌上启用了imap ..我也已经看过php的imap_open。我搞砸了插件,看看它是如何为imap_open方法准备连接字符串的!我编辑了我的问题来展示这一点。此外,我发现这个http://forums.phpfreaks.com/topic/99250-solved-imap-open-imap-connection-broken-problem/,但林不知道它的问题,可能不得不尝试一下! – LogixMaster

-1
class EmailConfig { 
    public $gmail = array(
     'host' => 'ssl://smtp.gmail.com', 
     'port' => 465, 
     'username' => '[email protected]', 
     '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/#

+0

我想从Gmail使用Imap阅读电子邮件不通过Apache服务器发送电子邮件。感谢虽然:) – LogixMaster

相关问题