Page 1 of 1

php imap_open() function not working.

Posted: Sun Jan 25, 2004 12:34 am
by SlatFats
Why am I having problems with this? I have asked a number of different places and can't seem to find my answer.

I have also had many people mention something about the quotations around the server name. Here's my script. When I remove the double quotes I get a 500 internal server error...when I leave the double quotes in, I get an unable to open stream message.

Code: Select all

<?php
/***************************************************************************
 *                                index.php
 *                            -------------------
 *   begin                : Saturday, Aug 16, 2003
 *   copyright            : (C) 2001 The phpBB Group
 *   email                : support@phpbb.com
 *
 *   $Id: mailbox.php,v 1.0 2003/08/16 13:37:40 slatfats Exp $
 *
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//

//
// Start output of page
//
$page_title = "Mailbox";
include($phpbb_root_path . 'includes/page_header.'.$phpEx);

$template->set_filenames(array(
	'body' => 'mailbox.tpl')
);

//
// Look up mail server settings
//
$sql = "SELECT * FROM phpbb_user_mail WHERE user_id = " . $userdata&#1111;'user_id'];
if( !($result = $db->sql_query($sql)) )
&#123;
	message_die(GENERAL_ERROR, 'Trouble fetching mailserver data', '', __LINE__, __FILE__, $sql);
&#125;
$row = $db->sql_fetchrow($result);
$mail_server = $row&#1111;'mail_server'];
$server_type = $row&#1111;'server_type'];
$server_login = $row&#1111;'server_login'];
$server_pass = $row&#1111;'server_pass'];
$delete_msgs = $row&#1111;'delete_msgs'];

if ($server_type == '1')
&#123;
   $mail_server = '"&#123;' . $mail_server . ':110/pop3&#125;INBOX"';
&#125;

if ($server_type == '2')
&#123;
   $mail_server = '"&#123;' . $mail_server . '&#125;"';
&#125;

$inbox = imap_open ($mail_server, "$server_login", "$server_pass");

if ( isset($HTTP_GET_VARS&#1111;'inbox']) && !isset($HTTP_GET_VARS&#1111;'read']) )
&#123;
	$total = imap_num_msg($inbox);
	for($i = $total; $i > 0; $i--)
	&#123;
  // get header and structure
  $headers = imap_header($inbox, $i);
  $structure = imap_fetchstructure($inbox, $i);

  for ($i = 1; $i < count($headers); $i++)
  &#123;
  	$email_msg = ($i-1);
  	$msg_links = '<a href="' . append_sid("mailbox.$phpEx?read&msg=$i") . '" class="gen">' . $headers&#1111;$email_msg] . '</a><br /><br />';

  	$template->assign_block_vars("inbox", array(
    "MESSAGE_LINKS" => $msg_links)
  	);
  &#125;
	&#125;
&#125;

if ( isset($HTTP_GET_VARS&#1111;'read']) && !isset($HTTP_GET_VARS&#1111;'inbox']) )
&#123;
	if ( isset($HTTP_GET_VARS&#1111;'msg']) )
	&#123;
  $msg = intval($HTTP_GET_VARS&#1111;'msg']);
	&#125;
	else
	&#123;
  header ("Location: $PHP_SELF?inbox");
	&#125;

	$message = imap_header($get_messages);
	$from = $message->from;
	$to = $message->to;
	$date = $message->Date;
	$subject = $message->Subject;
	$msg_text = imap_body($get_messages, $msg);

	$template->assign_block_vars("read_mail", array(
  "FROM" => $from,
  "TO" => $to,
  "DATE" => $date,
  "SUBJECT" => $subject,
  "MSG_TEXT" => $msg_text
  )
	);
&#125;

//
// Generate the page
//
$template->pparse('body');

include($phpbb_root_path . 'includes/page_tail.'.$phpEx);

?>

Posted: Sun Jan 25, 2004 1:31 pm
by Gen-ik
Try changing this line...
$inbox = imap_open ($mail_server, "$server_login", "$server_pass");

to this...
$inbox = imap_open ($mail_server."INBOX", $server_login, $server_pass);

...not sure if that will correct the problem but it's worth a try. You also need to make sure the server address is correct and that the server is either a POP3 or NNTP server... ask your Server Provider if you are unsure.