The following PHP_IMAP script is echoing an error; how do I hide the error from showing?

jvutechnc
jvutechnc used Ask the Experts™
on
The error messages are expected because my mailbox is empty, but I don't want them to show up.

Notice: Unknown: Mailbox is empty (errflg=1) in Unknown on line 0
Notice: Unknown: Sequence out of range (errflg=2) in Unknown on line 0

Thank you!!
<?php
include("dbconnect.php");
function translate_object($obj){
 return $obj->mailbox.'@'.$obj->host;

}



/* connect to server */
	$hostname = '{10.2.1.248:995/pop3/ssl/novalidate-cert}INBOX';
	$username = 'xxxxxx';
	$password = 'xxxxxx';

/* try to connect */
	$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to server: ' . imap_last_error());

/* grab emails */
	$emails = imap_search($inbox,'ALL');

	$headers = imap_headers($inbox);
	
	$numEmails = sizeof($headers);

	for($i = 1; $i < $numEmails+1; $i++)

	{

$mailHeader = @imap_headerinfo($inbox, $i);

$from = $mailHeader->reply_toaddress;

$subject = strip_tags($mailHeader->subject);

$body = htmlentities(imap_body($inbox, $i));

$date = $mailHeader->date;

$rows = "SELECT * FROM requests";
$result = mysql_query($rows);
$num=mysql_numrows($result);

$query = "INSERT INTO requests (`date`, `from`, `subject`, `message`) VALUES ('".date("D d M H:i")."','$from', '$subject', '".mysql_real_escape_string($body)."')";


	} 

imap_delete($inbox,'1:*');
imap_expunge($inbox);



/* close the connection */
	imap_close($inbox);

?>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Open the php.ini file.
In this file search for the phrase "error_reporting = E_ALL" (without quotation marks).
Replace this with "error_reporting = E_ALL & ~E_NOTICE & ~E_WARNING" (without quotation marks).
Restart your web server.

Author

Commented:
thanks, I'll try that.   Wow, this change seems drastic though and will effect all my scripts.   Is there something I can add to the script to only affect the script above I've attached?

Author

Commented:
nevermind, I just found out about

error_reporting(E_ALL ^ E_NOTICE);

I've placed it in that script now.


Author

Commented:
Thank you.  I added the code to my script and it worked.  I decided not to put it in php.ini.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial