PHP получение писем из Outlook
Всем привет! Народ, столкнулся вот с такой проблемой:
Есть на работе почтовый ящик. Из него нужно каким то образом получать письма с вложениями.
Сделал на php вот такую вот страницу:
<?
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
$APPLICATION->SetTitle("Title");
if (!$USER->IsAuthorized()) {
$APPLICATION->AuthForm('');
}
?>
<?
class Email_reader {
// imap server connection
public $conn;
// inbox storage and inbox message count
private $inbox;
private $msg_cnt;
// email login credentials
private $server = '<сервер>';
private $user = '<логин>';
private $pass = '<пароль>';
private $port = 143; // adjust according to server settings
private $hostname = '{<сервер>:143/imap/ssl}INBOX';
//private $hostname = '{<сервер>:143/imap/novalidate-cert}INBOX';
private $username = '<логин>';
private $password = '<пароль>';
// connect to the server and get the inbox emails
function __construct() {
$this->connect();
//$this->inbox();
}
// close the server connection
function close() {
$this->inbox = array();
$this->msg_cnt = 0;
imap_close($this->conn);
}
// open the server connection
// the imap_open function parameters will need to be changed for the particular server
// these are laid out to connect to a Dreamhost IMAP server
function connect() {
//$this->conn = imap_open('{'.$this->server.':'.$this->port.'/notls}', $this->user, $this->pass);
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to mail.nsd.ru: ' .imap_last_error());
}
// move the message to a new folder
function move($msg_index, $folder='INBOX.Processed') {
// move on server
imap_mail_move($this->conn, $msg_index, $folder);
imap_expunge($this->conn);
// re-read the inbox
$this->inbox();
}
// get a specific message (1 = first email, 2 = second email, etc.)
function get($msg_index=NULL) {
if (count($this->inbox) <= 0) {
return array();
}
elseif ( ! is_null($msg_index) && isset($this->inbox[$msg_index])) {
return $this->inbox[$msg_index];
}
return $this->inbox[0];
}
// read the inbox
function inbox() {
$this->msg_cnt = imap_num_msg($this->conn);
$in = array();
for($i = 1; $i <= $this->msg_cnt; $i++) {
$in[] = array(
'index' => $i,
'header' => imap_headerinfo($this->conn, $i),
'body' => imap_body($this->conn, $i),
'structure' => imap_fetchstructure($this->conn, $i)
);
}
$this->inbox = $in;
}
}
$reader = new Email_reader();
//phpinfo();
?>
<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");?>
Открываю страницу в браузере, получаю вот такую ошибку:
Cannot connect to <имя_сервера>: Can't open mailbox : no such mailbox
Кто-нибудь сталкивался с таким? Как это лечится. В php.ini расширение php_imap.dll раскомментировано. Веб-сервер Apache перезапускал. Помогите кто может пожалуйста. CMS: 1C-Bitrix