Ignore Warning

Im trying to authenticate against a mail server for login, so if the user enters the correct username and password for their mailbox then it will let them in, so Ive done the following code:-
<?php
	if (!imap_open('{outlook.office365.com:993/imap/ssl/novalidate-cert}', 'myusername', 'mypassword')) {
		echo "Failed";
	} else {
		echo "Success";
	}	
?>

Open in new window


My code works great and returns "Success" if it has the correct username and password, however if I enter an incorrect username and/or password I get a HUGE warning message up telling me its failed.
Warning: imap_open(): Couldn't open stream {outlook.office365.com:993/imap/ssl/novalidate-cert}

I know that its failed but thats the point, I dont want to switch down the error reporting as Im still developing the site so want to see error and warnings.

I through I could put it in a try/catch however it still displays the warning message.

Ive tried going through the php manual for imap_open to see if there is an ignore warnings options, but there doesn't seem to be one.

Any ideas how I can ignore the warnings
tonelm54Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
You can handle this two ways, and either is OK as long as you put some comments into the code to make sure there is a clear understanding of what's going on.

You can use the @ prepended to the function call.  This will suppress all messages from the function.

You can lower the error reporting level or suppress the display.  Before the function call, ini_set('display_errors', FALSE); and after the function call, ini_set('display_errors', TRUE);

More here:
http://php.net/manual/en/language.operators.errorcontrol.php

The risk in any of these strategies is that there could be some other error that causes a fatal condition, and when that happens you may get a silent failure, hence the advice to document this carefully with comments in the code.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.