Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tapping errors messages

Status
Not open for further replies.

wiser3

Programmer
Joined
Jun 3, 2003
Messages
358
Location
CA
Is there any way to prevent php syntax error messages from printing to the browser screen?

I'm using the mail function to send email. If someone enters an incorrect address like someonesomewhere.com (missing the @ symbol) i get this on the screen;

Warning: mail(): SMTP server response: 501 Syntax error, parameters in command &quot;RCPT TO:< someonesomewhere.com>&quot; unrecognized or missing in u:\inetpub\ on line 222

How can i prevent this from appearing and put in my own error message instead?
 
Something like
Code:
if (!@mail($to, $subject, $message, $headers))
{
    echo &quot;Ouch. Something went terribly wrong.&quot;;
}

//Daniel
 
The &quot;@&quot; error-suppression operator will certainly do what you want.

I generally recommend against using it. It masks all errors, including ones you really might want to see.

I strongly recommend that you check the email address for well-formedness before using it. Check out faq434-2408.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
This is a philosophical issue.
There are different ways to approach this topic/question. Daniels solution works, it just silences the error message and puts a nicer message on the screen.
However, I would suggest that you check out the entered e-mail before trying to send to a non-existing host.
Your description of a wrongly entered address indicates that you don't check the format. There is an excellent FAQ by sleipnir214 faq434-2408 that deals with validating the input.
One of the things you learn - hopefully from someones advice rather than through bitter experience - is that you cannot trust user input. Validation keeps your system safe, so make it a habit.
 
Thanks guys, that makes a whole lot of sense and the function in the faq is perfect.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top