Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Enhancing a Simple PHP Application Integrating Validation Errors Displaying the Error Message

potential improvement

Randy Hoyt

If the user fails to include ".com" in the email field, he will receive an error message like this: "There was a problem sending the email: Could not instantiate mail function." This doesn't seem ideal because--at least from the perspective of the average user--it's cryptic. Also, from a developer's perspective, it's not an intended error message. So, I think it would be useful to add to the conditional statement. Instead of:

    if (!isset($error_message) && !$mail->ValidateAddress($email){
      $error_message = "You must specify a valid email address.";
    }

it should be:

    if (!isset($error_message) && (!$mail->ValidateAddress($email) OR stripos($email, '.com') == FALSE)){
      $error_message = "You must specify a valid email address.";
    }

Now, I'm no PHP wiz so please chime in if this will break anything or cause unintended results. I've tested this locally and it seems to work. Anyway, hope this helps!

-James Cool