Using a function to validate email-addresses
<p>I'm new to custom functions in PHP. I'm using the following function, from a book, to validate email addresses:</p>

<pre><code>&lt;?php

$email = $_POST['email'];

function is_email($email) {
// Checks for proper email format
    if (!preg_match('/^[A-Za-z0-9!#$%&amp;\'*+-/=?ˆ_`{|}~]+@[A-Za-z0-9]+(\.[A-Za-z0-9]+)+[A-Za-z]%/', $email)) 
    {
        return false;
    } 
    else 
    {
       return true;
    }
}

?&gt;

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Validate Email&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

    &lt;form method="post" action="&lt;?php echo $_SERVER['PHP_SELF'] ?&gt;"&gt;
    Email&lt;input type="text" name="email"&gt;&lt;/input&gt;
    &lt;input type="submit" value="Send"&gt;
    &lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Now, I want to show a message if the email was correct, and show a message if it wasn't correct. I don't really know know what to do next. I've already tried the following, before the ?> closing tag:</p>

<pre><code>if (is_email($email) == true) {
    echo "Right";
}
elseif (is_email($email) == false) {
    echo "Wrong";
}
</code></pre>

<p>But this doesn't do anything. What's the solution for this?</p>
