本文整理汇总了PHP中imap_open函数的典型用法代码示例。如果您正苦于以下问题:PHP imap_open函数的具体用法?PHP imap_open怎么用?PHP imap_open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imap_open函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: readEmails
public function readEmails($sentTo = null, $bodyPart = null)
{
$host = '{imap.gmail.com:993/imap/ssl}INBOX';
$spinner = new Spinner('Could not connect to Imap server.', 60, 10000);
$inbox = $spinner->assertBecomesTrue(function () use($host) {
return @imap_open($host, $this->email, $this->password);
});
$emails = imap_search($inbox, 'TO ' . ($sentTo ? $sentTo : $this->email));
if ($emails) {
$messages = [];
foreach ($emails as $n) {
$structure = imap_fetchstructure($inbox, $n);
if (!$bodyPart) {
$part = $this->findPart($structure, function ($part) {
return $part->subtype === 'HTML';
});
} elseif (is_callable($bodyPart)) {
$part = $this->findPart($structure, $bodyPart);
} else {
$part = $bodyPart;
}
$hinfo = imap_headerinfo($inbox, $n);
$subject = $hinfo->subject;
$message = ['subject' => $subject, 'body' => imap_fetchbody($inbox, $n, $part)];
$messages[] = $message;
}
return $messages;
} else {
return [];
}
}
示例2: connect
/**
*Opens a connection to the server
*@return boolean
*/
function connect($server, $port, $login, $password)
{
$option = "/service=" . $this->_protocol;
if ($this->_ssl) {
$option .= "/ssl";
}
if ($this->_tls_on) {
$option .= "/tls";
} else {
$option .= "/notls";
}
if ($this->_self_cert) {
$option .= "/novalidate-cert";
}
if (eregi("google", $server)) {
//Fix from Jim Hodgson http://www.jimhodgson.com/2006/07/19/postie/
$server_string = "{" . $server . ":" . $port . $option . "}INBOX";
} else {
$server_string = "{" . $server . ":" . $port . $option . "}";
}
$this->_connection = imap_open($server_string, $login, $password);
if ($this->_connection) {
$this->_connected = true;
}
return $this->_connected;
}
示例3: emailDeliverFailBySubject
public static function emailDeliverFailBySubject($subject)
{
$mailcnf = "outlook.office365.com:993/imap/ssl/novalidate-cert";
$username = MAILACCOUNT;
$pw = MAILPASSWORD;
$conn_str = "{" . $mailcnf . "}INBOX";
$inbox = imap_open($conn_str, $username, $pw) or die('Cannot connect to mail: ' . imap_last_error());
/* grab emails */
$emails = imap_search($inbox, 'SUBJECT "Undeliverable: ' . $subject . '"');
$failedInfo = [];
/* if emails are returned, cycle through each... */
if ($emails) {
/* for every email... */
foreach ($emails as $email_number) {
/* get information specific to this email */
$body = imap_fetchbody($inbox, $email_number, 2);
$list = split('; ', $body);
$sender = $list[2];
$sender_email = explode("\n", $sender)[0];
array_push($failedInfo, trim($sender_email));
}
}
/* close the connection */
imap_close($inbox);
return $failedInfo;
}
示例4: authenticate
function authenticate($username, $passwd)
{
error_reporting(error_reporting() - 2);
if ($GLOBALS['phpgw_info']['server']['mail_login_type'] == 'vmailmgr') {
$username = $username . '@' . $GLOBALS['phpgw_info']['server']['mail_suffix'];
}
if ($GLOBALS['phpgw_info']['server']['mail_server_type'] == 'imap') {
$GLOBALS['phpgw_info']['server']['mail_port'] = '143';
} elseif ($GLOBALS['phpgw_info']['server']['mail_server_type'] == 'pop3') {
$GLOBALS['phpgw_info']['server']['mail_port'] = '110';
} elseif ($GLOBALS['phpgw_info']['server']['mail_server_type'] == 'imaps') {
$GLOBALS['phpgw_info']['server']['mail_port'] = '993';
} elseif ($GLOBALS['phpgw_info']['server']['mail_server_type'] == 'pop3s') {
$GLOBALS['phpgw_info']['server']['mail_port'] = '995';
}
if ($GLOBALS['phpgw_info']['server']['mail_server_type'] == 'pop3') {
$mailauth = imap_open('{' . $GLOBALS['phpgw_info']['server']['mail_server'] . '/pop3' . ':' . $GLOBALS['phpgw_info']['server']['mail_port'] . '}INBOX', $username, $passwd);
} elseif ($GLOBALS['phpgw_info']['server']['mail_server_type'] == 'imaps') {
// IMAPS support:
$mailauth = imap_open('{' . $GLOBALS['phpgw_info']['server']['mail_server'] . "/ssl/novalidate-cert" . ':993}INBOX', $username, $passwd);
} elseif ($GLOBALS['phpgw_info']['server']['mail_server_type'] == 'pop3s') {
// POP3S support:
$mailauth = imap_open('{' . $GLOBALS['phpgw_info']['server']['mail_server'] . "/ssl/novalidate-cert" . ':995}INBOX', $username, $passwd);
} else {
/* assume imap */
$mailauth = imap_open('{' . $GLOBALS['phpgw_info']['server']['mail_server'] . ':' . $GLOBALS['phpgw_info']['server']['mail_port'] . '}INBOX', $username, $passwd);
}
error_reporting(error_reporting() + 2);
if ($mailauth == False) {
return False;
} else {
imap_close($mailauth);
return True;
}
}
示例5: connect
/**
* Make a connect with a imap or pop3 mail server
*
* @param array $params Parameters for making connection
*/
function connect($params)
{
# Storing server type
$server_type = $params['type'];
# Determine port to use
$port = $params['type'] == "pop3" ? $params['secure'] ? 995 : 110 : ($params['secure'] ? 993 : 143);
# Form server string
$server = "{" . $params['server'] . ":{$port}/" . $params['type'];
$server .= $params['secure'] ? "/ssl" : "";
$server .= "}";
# Attempt connection
$this->conn = @imap_open($server . $params['mailbox'], $params['username'], $params['password']);
# If failure also try with "notls" and "novalidate-cert" option
if (!$this->conn) {
$server = str_replace("}", "/notls}", $server);
$this->conn = @imap_open($server . $params['mailbox'], $params['username'], $params['password']);
}
if (!$this->conn) {
$server = str_replace("/notls}", "/novalidate-cert}", $server);
$this->conn = @imap_open($server . $params['mailbox'], $params['username'], $params['password']);
}
# Connection made
if ($this->conn) {
# Keep track of server string
$this->server = $server;
# Retrieve number of messages in mailbox
$this->num_msgs = imap_num_msg($this->conn);
return true;
} else {
# If connection not made then log error
return false;
}
}
示例6: __construct
/**
* Opens up imap connection to the specified url
* @param $url String - mail server url
* @param $username String - user name of the mail box
* @param $password String - pass word of the mail box
* @param $baseUrl Optional - url of the mailserver excluding folder name.
* This is used to fetch the folders of the mail box
*/
function __construct($url, $username, $password, $baseUrl=false) {
$boxUrl = $this->convertCharacterEncoding(html_entity_decode($url),'UTF7-IMAP','UTF-8'); //handle both utf8 characters and html entities
$this->mBoxUrl = $boxUrl;
$this->mBoxBaseUrl = $baseUrl; // Used for folder List
$this->mBox = @imap_open($boxUrl, $username, $password);
$this->isError();
}
示例7: openImap
/**
* @return resource
*/
protected function openImap($server = null, $port = null, $protocol = null, $username = null, $password = null, $inbox = null)
{
if (!$server) {
$server = $this->container->getParameter('ephp_imap.server');
}
if (!$port) {
$port = $this->container->getParameter('ephp_imap.port');
}
if (!$protocol) {
$protocol = $this->container->getParameter('ephp_imap.protocol');
}
if (!$username) {
$username = $this->container->getParameter('ephp_imap.username');
}
if (!$password) {
$password = $this->container->getParameter('ephp_imap.password');
}
$connection = '{' . $server . ':' . $port . '/' . $protocol . '}' . $inbox;
try {
$this->inbox = imap_open($connection, $username, $password);
return $this->inbox;
} catch (\Exception $e) {
throw $e;
}
}
示例8: open
function open($hostname, $username, $password)
{
$this->con = imap_open($hostname, $username, $password);
if (!$this->con) {
throw new \Exception("Unable to open connection to: " . $hostname . ' error: ' . imap_last_error());
}
}
示例9: imap_test_connect
function imap_test_connect($host,$user,$pass,$timeout=-1,$protocol="imap",$port=-1,$ssl=false,$debug=false)
{
global $NATS;
if ($timeout>0) $timeout=$timeout; // use specific for test if set
else
{
// otherwise use system if available
if (isset($NATS)) $timeout=$NATS->Cfg->Get("test.imap.timeout",0);
if ($timeout<=0) $timeout=0; // unset specifically or in environment
}
if ($timeout>0) imap_timeout(IMAP_OPENTIMEOUT,$timeout);
if ($port<=0)
{
$port=143; // default
if ( ($protocol=="imap") && ($ssl) ) $port=993;
else if ($protocol=="pop3")
{
if ($ssl) $port=995;
else $port=110;
}
}
$mailbox="{".$host.":".$port."/service=".$protocol;
if ($ssl) $mailbox.="/ssl";
$mailbox.="/novalidate-cert";
$mailbox.="}INBOX";
if ($debug) echo $user.":".$pass."@".$mailbox."\n";
$imap=@imap_open($mailbox,$user,$pass);
if ($imap===false) return 0;
@imap_close($imap);
return 1;
}
示例10: connect
function connect()
{
$this->stream = imap_open($this->mailbox, $this->username, $this->password);
if ($this->stream === false) {
trigger_error(sprintf("Invalid IMAP stream (Mailbox: %s / Username: %s)", $this->mailbox, $this->username), E_USER_WARNING);
}
}
示例11: Logon
function Logon($username, $domain, $password)
{
$this->_wasteID = false;
$this->_sentID = false;
$this->_username = $username;
$this->_domain = $domain;
$this->_password = $password;
if (!$this->getLdapAccount()) {
return false;
}
$this->_server = "{" . $this->_KolabHomeServer . ":" . KOLAB_IMAP_PORT . "/imap" . KOLAB_IMAP_OPTIONS . "}";
$this->Log("Connecting to " . $this->_server);
if (!function_exists("imap_open")) {
debugLog("ERROR BackendIMAP : PHP-IMAP module not installed!!!!!");
$this->Log("module PHP imap not installed ");
}
// open the IMAP-mailbox
$this->_mbox = @imap_open($this->_server, $username, $password, OP_HALFOPEN);
$this->_mboxFolder = "";
if ($this->_mbox) {
debugLog("KolabBackend Version : " . KOLABBACKEND_VERSION);
debugLog("KolabActiveSyndData Version : " . KOLABACTIVESYNCDATA_VERSION);
$this->Log("KolabBackend Version : " . KOLABBACKEND_VERSION);
$this->Log("KolabActiveSyndData Version : " . KOLABACTIVESYNCDATA_VERSION);
$this->Log("IMAP connection opened sucessfully user : " . $username);
// set serverdelimiter
$this->_serverdelimiter = $this->getServerDelimiter();
return true;
} else {
$this->Log("IMAP can't connect: " . imap_last_error() . " user : " . $this->_user . " Mobile ID:" . $this->_devid);
return false;
}
}
示例12: fetch
public function fetch(MailCriteria $criteria, $callback)
{
$mailbox = @imap_open('{' . $this->host . ':' . $this->port . '}INBOX', $this->username, $this->password);
if (!$mailbox) {
throw new ImapException("Cannot connect to imap server: {$this->host}:{$this->port}'");
}
$this->checkProcessedFolder($mailbox);
$emails = $this->fetchEmails($mailbox, $criteria);
if ($emails) {
foreach ($emails as $emailIndex) {
$overview = imap_fetch_overview($mailbox, $emailIndex, 0);
$message = imap_body($mailbox, $emailIndex);
$email = new Email($overview, $message);
$processed = $callback($email);
if ($processed) {
$res = imap_mail_move($mailbox, $emailIndex, $this->processedFolder);
if (!$res) {
throw new \Exception("Unexpected error: Cannot move email to ");
break;
}
}
}
}
@imap_close($mailbox);
}
示例13: connect
/**
* Opens a connection to the server
* @return boolean
*/
function connect($server, $port, $login, $password)
{
$option = "/service=" . $this->_protocol;
if ($this->_ssl) {
$option .= "/ssl";
}
if ($this->_tls_on) {
$option .= "/tls";
} else {
$option .= "/notls";
}
if ($this->_self_cert) {
$option .= "/novalidate-cert";
}
if (preg_match("/google|gmail/i", $server)) {
//Fix from Jim Hodgson http://www.jimhodgson.com/2006/07/19/postie/
$this->_server_string = "{" . $server . ":" . $port . $option . "}INBOX";
} else {
$this->_server_string = "{" . $server . ":" . $port . $option . "}";
}
$this->_connection = imap_open($this->_server_string, $login, $password);
if ($this->_connection) {
$this->_connected = true;
} else {
LogInfo("imap_open failed: " . imap_last_error());
}
return $this->_connected;
}
示例14: getInbox
private function getInbox($user_id)
{
if (!$this->inbox) {
$this->inbox = imap_open($this->hostname, 'u' . $user_id . '@' . $this->domain, $user_id) or die('Cannot connect to Notify system');
}
return $this->inbox;
}
示例15: Auth
/**
* Authenticate user/password
*
* @access public
* @param string $user User's name or email
* @param string $password User's password
* @return mixed Array of user's information otherwise Jaws_Error
*/
function Auth($user, $password)
{
if (!function_exists('imap_open')) {
return Jaws_Error::raiseError('Undefined function imap_open()', __FUNCTION__);
}
$mbox = @imap_open('{' . $this->_Server . ':' . $this->_Port . ($this->_SSL ? '/imap/ssl' : '') . '}INBOX', $user, $password);
if ($mbox) {
@imap_close($mbox);
$result = array();
$result['id'] = strtolower('imap:' . $user);
$result['internal'] = false;
$result['username'] = $user;
$result['superadmin'] = false;
$result['internal'] = false;
$result['groups'] = array();
$result['nickname'] = $user;
$result['concurrents'] = 0;
$result['email'] = '';
$result['url'] = '';
$result['avatar'] = 'gadgets/Users/Resources/images/photo48px.png';
$result['language'] = '';
$result['theme'] = '';
$result['editor'] = '';
$result['timezone'] = null;
return $result;
}
return Jaws_Error::raiseError(_t('GLOBAL_ERROR_LOGIN_WRONG'), __FUNCTION__);
}