shahariaazam / cakephp-datasource-imap
CakePHP 的 Imap 数据源插件
2.0
2014-08-28 01:12 UTC
Requires
This package is auto-updated.
Last update: 2024-09-06 09:17:39 UTC
README
CakePHP (2.x) 的自定义数据源,用于与您的邮件服务器通过 IMAP 功能进行交互。
将 ImapSource.php 数据源放入您的 app/Model/Datasource
目录,并按以下方式设置。
<?php //app/Model/CustomEmail.php class CustomEmail extends AppModel { // Important: public $useDbConfig = 'myCustomEmail'; public $useTable = false; // Whatever: public $displayField = 'subject'; public $limit = 10; // Semi-important: // You want to use the datasource schema, and still be able to set // $useTable to false. So we override Cake's schema with that exception: function schema($field = false) { if (!is_array($this->_schema) || $field === true) { $db =& ConnectionManager::getDataSource($this->useDbConfig); $db->cacheSources = ($this->cacheSources && $db->cacheSources); $this->_schema = $db->describe($this, $field); } if (is_string($field)) { if (isset($this->_schema[$field])) { return $this->_schema[$field]; } else { return null; } } return $this->_schema; } }
现在您需要在 app/Config/Database.php
中定义凭据,如下所示。
<?php //app/Config/Database.php public $myCustomEmail = array( 'datasource' => 'ImapSource', 'server' => 'YourIMAPServerHost', 'username' => 'IMAPServerUsername', 'password' => 'yourIMAPPassword', 'port' => 'IMAPServerPort', 'ssl' => true, 'encoding' => 'UTF-8', 'error_handler' => 'php', 'auto_mark_as' => array( 'Seen', // 'Answered', // 'Flagged', // 'Deleted', // 'Draft', ), );
现在从您的控制器中直接访问您的邮件,如下所示
<?php // app/Controller/MailsController.php //your controller codes ... public function index() { $this->loadModel('CustomEmail'); $emails = $this->CustomEmail->find('first'); var_dump($emails); die(); }
现在您将收到邮件。查看调试输出。如果您有任何问题,请随时给我发邮件到 shaharia.azam@gmail.com