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

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!!
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
<?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);

?>

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

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.
Random Solutions  
 
programming4us programming4us