We help IT Professionals succeed at work.
Get Started

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

jvutechnc asked
Last Modified: 2013-11-10
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!!
function translate_object($obj){
 return $obj->mailbox.'@'.$obj->host;


/* connect to server */
	$hostname = '{}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);

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



/* close the connection */


Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE