How do I...

63 views
Skip to first unread message

Ian S

unread,
Nov 4, 2008, 5:47:35 AM11/4/08
to php-email-address-validation
...download the code for email validation?

Ian

David Child

unread,
Nov 4, 2008, 6:38:49 AM11/4/08
to php-email-addr...@googlegroups.com
Hi Ian,

The code is hosted with Google Code at:
http://code.google.com/p/php-email-address-validation/

From there, click "Source" and you have two options to grab the code.
You can use the SVN repository if you like (instructions are on the
page when you click "Source") or you can click "Browse" to view the
code online.

Regards
Dave

Ian Sandell

unread,
Nov 4, 2008, 7:03:28 AM11/4/08
to php-email-addr...@googlegroups.com
Dave,

Thanks for prompt reply. It would have taken me a long time to get
there.

The code looks ideal, and I like all the comments.

Thanks again.

Ian

David Child

unread,
Nov 4, 2008, 7:11:35 AM11/4/08
to php-email-addr...@googlegroups.com
Hi Ian,

My pleasure. I'll try to remember to add some instructions for
downloading to the project page - you're not the first person to ask
about this.

Dave

Bloglegend

unread,
Dec 4, 2008, 7:38:24 PM12/4/08
to php-email-address-validation
Dave,

I know your a genius when it comes to php validation, and this will
probably take you 2 minutes to figure out. I on the other hand have
been trying to validate this form for more than a week. I have gone
through forum after forum, book after book, and finally came across
your blog. I am knew to php, so pardon my ignorance as I go through
the learning process. Here is my script could you please show me how
to add email validation to it.

Form

<?php

$to = 'm...@mywebsite.com';
$header = $_POST['emailAddress']
$subject = $_POST['inquiryOptions'];
$name = $_POST['fullName'];
$comment = $_POST['thoughts'];
$header = $_POST['emailAddress'];
$message = "From: $name\nSender e-mail address: $header\nRegarding:
$subject\n\nMessage:\n$comment\n";

if ($header =="") {
echo "<meta http-equiv=\"refresh\"
content=\"0;URL=error.html\">";
exit;
}
$success= mail($to, $subject, "From: <$header>");

if ($success)
{
echo "<meta http-equiv=\"refresh\"
content=\"0;Url=thankyou.php\">";
}
else
{
echo "<meta http-equv=\"refresh\"
content=\"0;URL=failure.html\">";

}

?>

/*

EmailAddressValidator Class
http://code.google.com/p/php-email-address-validation/

Released under New BSD license
http://www.opensource.org/licenses/bsd-license.php

Sample Code
----------------
$validator = new EmailAddressValidator;
if ($validator->check_email_address('te...@example.org')) {
// Email address is technically valid
}

*/

class EmailAddressValidator {

/**
* Check email address validity
* @param strEmailAddress Email address to be checked
* @return True if email is valid, false if not
*/
public function check_email_address($strEmailAddress) {

// If magic quotes is "on", email addresses with quote
marks will
// fail validation because of added escape characters.
Uncommenting
// the next three lines will allow for this issue.
//if (get_magic_quotes_gpc()) {
// $strEmailAddress = stripslashes($strEmailAddress);
//}

// Control characters are not allowed
if (preg_match('/[\x00-\x1F\x7F-\xFF]/',
$strEmailAddress)) {
return false;
}

// Split it into sections using last instance of "@"
$intAtSymbol = strrpos($strEmailAddress, '@');
if ($intAtSymbol === false) {
// No "@" symbol in email.
return false;
}
$arrEmailAddress[0] = substr($strEmailAddress, 0,
$intAtSymbol);
$arrEmailAddress[1] = substr($strEmailAddress,
$intAtSymbol + 1);

// Count the "@" symbols. Only one is allowed, except
where
// contained in quote marks in the local part. Quickest
way to
// check this is to remove anything in quotes.
$arrTempAddress[0] = preg_replace('/"[^"]+"/'
,''
,$arrEmailAddress[0]);
$arrTempAddress[1] = $arrEmailAddress[1];
$strTempAddress = $arrTempAddress[0] . $arrTempAddress[1];
// Then check - should be no "@" symbols.
if (strrpos($strTempAddress, '@') !== false) {
// "@" symbol found
return false;
}

// Check local portion
if (!$this->check_local_portion($arrEmailAddress[0])) {
return false;
}

// Check domain portion
if (!$this->check_domain_portion($arrEmailAddress[1])) {
return false;
}

// If we're still here, all checks above passed. Email is
valid.
return true;

}

/**
* Checks email section before "@" symbol for validity
* @param strLocalPortion Text to be checked
* @return True if local portion is valid, false if not
*/
protected function check_local_portion($strLocalPortion) {
// Local portion can only be from 1 to 64 characters,
inclusive.
// Please note that servers are encouraged to accept
longer local
// parts than 64 characters.
if (!$this->check_text_length($strLocalPortion, 1, 64)) {
return false;
}
// Local portion must be:
// 1) a dot-atom (strings separated by periods)
// 2) a quoted string
// 3) an obsolete format string (combination of the above)
$arrLocalPortion = explode('.', $strLocalPortion);
for ($i = 0, $max = sizeof($arrLocalPortion); $i < $max; $i
++) {
if (!preg_match('.^('
. '([A-Za-z0-9!#$%&\'*+/=?^_`{|}
~-]'
. '[A-Za-z0-9!#$%&\'*+/=?^_`{|}~-]
{0,63})'
.'|'
. '("[^\\\"]{0,62}")'
.')$.'
,$arrLocalPortion[$i])) {
return false;
}
}
return true;
}

/**
* Checks email section after "@" symbol for validity
* @param strDomainPortion Text to be checked
* @return True if domain portion is valid, false if not
*/
protected function check_domain_portion($strDomainPortion) {
// Total domain can only be from 1 to 255 characters,
inclusive
if (!$this->check_text_length($strDomainPortion, 1, 255))
{
return false;
}
// Check if domain is IP, possibly enclosed in square
brackets.
if (preg_match('/^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?
[0-9])'
.'(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9]))
{3}$/'
,$strDomainPortion) ||
preg_match('/^\[(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?
[0-9])'
.'(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}\]
$/'
,$strDomainPortion)) {
return true;
} else {
$arrDomainPortion = explode('.', $strDomainPortion);
if (sizeof($arrDomainPortion) < 2) {
return false; // Not enough parts to domain
}
for ($i = 0, $max = sizeof($arrDomainPortion); $i <
$max; $i++) {
// Each portion must be between 1 and 63
characters, inclusive
if (!$this->check_text_length($arrDomainPortion
[$i], 1, 63)) {
return false;
}
if (!preg_match('/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}
[A-Za-z0-9])|'
.'([A-Za-z0-9]+))$/', $arrDomainPortion[$i])) {
return false;
}
}
}
return true;
}

/**
* Check given text length is between defined bounds
* @param strText Text to be checked
* @param intMinimum Minimum acceptable length
* @param intMaximum Maximum acceptable length
* @return True if string is within bounds (inclusive), false
if not
*/
protected function check_text_length($strText, $intMinimum,
$intMaximum) {
// Minimum and maximum are both inclusive
$intTextLength = strlen($strText);
if (($intTextLength < $intMinimum) || ($intTextLength >
$intMaximum)) {
return false;
} else {
return true;

Chris

unread,
Dec 5, 2008, 3:22:47 AM12/5/08
to php-email-addr...@googlegroups.com
I'm not Dave, but your answer lies in his first comment in the source.
$validator = new EmailAddressValidator;
if (!$validator->check_email_address($header)) {

     echo "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
     exit;
}
BTW, you assign the same value to $header twice.

In ALL things, strive for ><>,
Chris

David Child

unread,
Dec 5, 2008, 3:58:33 AM12/5/08
to php-email-addr...@googlegroups.com
That looks spot on, Chris.

Bloglegend - let us know if that works :)

Bloglegend

unread,
Dec 5, 2008, 8:15:02 PM12/5/08
to php-email-address-validation
Thank you Chris, and Dave for your prompt response.

I did plug in the code using the advise that you gave me, but now I'm
coming up with a parse error '>' on line 27. I know it's something
simple like a semi colon or a bracket, but I posted my code anyway
just in case I miss it. I am once again grateful for any advise that
you guys can give.
P.S
Chris that double $header post was a cut and paste error, I quickly
went back and checked. Thank you for pointing it out though.


<?php

$to = 'm...@mysite.com';
$subject = $_POST['inquiryOptions'];
$name = $_POST['fullName'];
$comment = $_POST['thoughts'];
$header = $_POST['emailAddress'];
$message = "From: $name\nSender e-mail address: $header\nRegarding:
$subject\n\nMessage:\n$comment\n";
/*

EmailAddressValidator Class
http://code.google.com/p/php-email-address-validation/

Released under New BSD license
http://www.opensource.org/licenses/bsd-license.php

Sample Code
----------------
$validator = new EmailAddressValidator;
if ($validator->check_email_address('t...@example.org')) {
// Email address is technically valid
}

*/
$validator = new EmailAddressValidator;
if (!$validator->check_email_address('$header')){
> echo "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
> exit;

}

if ($header =="")

{
echo "<meta http-equiv=\"refresh\"
content=\"0;URL=error.html\">";
exit;
}
$success= mail($to, $subject, $message, "From: <$header>");

if ($success) {
echo "<meta http-equiv=\"refresh\"
content=\"0;Url=success.html\">";
}
else {
echo "<meta http-equv=\"refresh\"
content=\"0;URL=failure.html\">";

}

?>

On Dec 5, 12:58 am, "David Child" <d...@addedbytes.com> wrote:
> That looks spot on, Chris.
>
> Bloglegend - let us know if that works :)
>
> On Fri, Dec 5, 2008 at 8:22 AM, Chris <jesdisci...@gmail.com> wrote:
> > I'm not Dave, but your answer lies in his first comment in the source.
>
> >> $validator = new EmailAddressValidator;
> >> if (!$validator->check_email_address($header)) {
> >>      echo "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
> >>      exit;
> >> }
>
> > BTW, you assign the same value to $header twice.
>
> > In ALL things, strive for ><>,
> > Chris
>
> > On Thu, Dec 4, 2008 at 9:08 PM, Bloglegend <blogleg...@gmail.com> wrote:
>
> >> Dave,
>
> >> I know your a genius when it comes to php validation, and this will
> >> probably take you 2 minutes to figure out.  I on the other hand have
> >> been trying to validate this form for more than a week.   I have gone
> >> through forum after forum, book after book, and finally came across
> >> your blog.  I am knew to php, so pardon my ignorance as I go through
> >> the learning process.  Here is my script could you please show me how
> >> to add email validation to it.
>
> >> Form
>
> >> <?php
>
> >> $to = '...@mywebsite.com';
> >>        if ($validator->check_email_address('t...@example.org')) {
> ...
>
> read more »

Bloglegend

unread,
Dec 5, 2008, 9:11:49 PM12/5/08
to php-email-address-validation
Guys I figured out that error. Again it was a cut and paste issue
which was quickly corrected when I removed the '>' that I copied from
Chris' code.

Now I'm getting this error code from line 42
Parse error: syntax error, unexpected T_STRING, expecting
T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' on line 42.

To make it easier to find line 42 begins like this:

public function check_email_address($strEmailAddress) {


On Dec 5, 12:58 am, "David Child" <d...@addedbytes.com> wrote:
> That looks spot on, Chris.
>
> Bloglegend - let us know if that works :)On Fri, Dec 5, 2008 at 8:22 AM, Chris <jesdisci...@gmail.com> wrote:
> > I'm not Dave, but your answer lies in his first comment in the source.
>
> >> $validator = new EmailAddressValidator;
> >> if (!$validator->check_email_address($header)) {
> >>      echo "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
> >>      exit;
> >> }
>
> > BTW, you assign the same value to $header twice.
>
> > In ALL things, strive for ><>,
> > Chris
>
> > On Thu, Dec 4, 2008 at 9:08 PM, Bloglegend <blogleg...@gmail.com> wrote:
>
> >> Dave,
>
> >> I know your a genius when it comes to php validation, and this will
> >> probably take you 2 minutes to figure out.  I on the other hand have
> >> been trying to validate this form for more than a week.   I have gone
> >> through forum after forum, book after book, and finally came across
> >> your blog.  I am knew to php, so pardon my ignorance as I go through
> >> the learning process.  Here is my script could you please show me how
> >> to add email validation to it.
>
> >> Form
>
> >> <?php
>
> >> $to = '...@mywebsite.com';
> >>        if ($validator->check_email_address('t...@example.org')) {

Chris

unread,
Dec 5, 2008, 10:25:26 PM12/5/08
to php-email-addr...@googlegroups.com
I'll have to remember to not quote my code over email anymore.

In your original source, the class is not contained by the <?php ?> tags; is that the entire source?  If not, please post it; syntax errors sometimes reside well above their point of detection.  Plus I think I need to run the script myself to find anything else.


In ALL things, strive for ><>,
Chris


Blog Legend

unread,
Dec 6, 2008, 6:18:52 AM12/6/08
to php-email-addr...@googlegroups.com
I'm sorry Chris I should have posted it with the <?php?> tags; but that is the entire code.  Everything works great until I add the email validation which I'm sure you will agree with me is the most important part. 

I posted the code below by itself, and then with validation. 

Thanks again for taking the time to look at this for me.
Bloglegend



Here is the code posted in its entirety:  (with limited validation this just checks to see if the email field is left blank)

<?php

$to = 'm...@atmysite.com';

$subject = $_POST['inquiryOptions'];
$name = $_POST['fullName'];
$comment = $_POST['thoughts'];
$header = $_POST['emailAddress'];
$message = "From: $name\nSender e-mail address: $header\nRegarding: $subject\n\nMessage:\n$comment\n";
 
if ($header =="")

     {
echo "<meta http-equiv=\"refresh\"
content=\"0;URL=error.html\">";
exit;
}
$success= mail($to, $subject, $message, "From: <$header>");


if  ($success) {
      echo "<meta http-equiv=\"refresh\"
      content=\"0;Url=success.html\">";

}
else {
echo "<meta http-equv=\"refresh\"
content=\"0;URL=failure.html\">";

}

 ?>


With full Validation

<?php

$to = 'm...@atmysite.com';

$subject = $_POST['inquiryOptions'];
$name = $_POST['fullName'];
$comment = $_POST['thoughts'];
$header = $_POST['emailAddress'];
$message = "From: $name\nSender e-mail address: $header\nRegarding: $subject\n\nMessage:\n$comment\n";
 
/*

        EmailAddressValidator Class
        http://code.google.com/p/php-email-address-validation/

        Released under New BSD license
        http://www.opensource.org/licenses/bsd-license.php

        Sample Code
        ----------------
        $validator = new EmailAddressValidator;
        if ($validator->check_email_address('t...@example.org')) {
            // Email address is technically valid
        }

    */
$validator = new EmailAddressValidator;
 if (!$validator->check_email_address('$header')){

      echo "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
      exit;

        }

   

if ($header =="")

     {
echo "<meta http-equiv=\"refresh\"
content=\"0;URL=error.html\">";
exit;
}
$success= mail($to, $subject, $message, "From: <$header>");


if  ($success) {
      echo "<meta http-equiv=\"refresh\"
      content=\"0;Url=success.html\">";

}
else {
echo "<meta http-equv=\"refresh\"
content=\"0;URL=failure.html\">";

}

?>




Chris

unread,
Dec 6, 2008, 8:27:13 PM12/6/08
to php-email-addr...@googlegroups.com
I haven't tested it yet because I'm struggling to find a working server I can use...  My home server is down for an unknown reason which I need to ask about and my deployment server isn't accepting uploads.  I forgot the login info to my friend's deployment server that I haven't needed in a long time.

While I work on that stuff, why did you highlight two of the lines in your second source?


In ALL things, strive for ><>,
Chris


Franchesca

unread,
Dec 6, 2008, 3:15:33 PM12/6/08
to php-email-addr...@googlegroups.com
I think the problem may be the way you are 'presenting' the comments at the
top of the code.

This:
/*
EmailAddressValidator Class
http://code.google.com/p/php-email-address-validation/

Released under New BSD license
http://www.opensource.org/licenses/bsd-license.php

Sample Code
----------------
$validator = new EmailAddressValidator;
if ($validator->check_email_address('t...@example.org')) {
// Email address is technically valid
}
*/

When I remove the -> after $validator something changes. This could be as
simple as commenting that code out differently than the way it is now.

Still, take it as you will as I am very very new to this and look at things
totally differently than most of you do most likely as I was an artist
turned programmer about 15 years ago.

Franchesca
> 9]|[1-9]?[0-9])){3}\]
> > >> $/'
> > >> ,$strDomainPortion)) {
> > >> return true;
> > >> } else {
> > >> $arrDomainPortion = explode('.',
> $strDomainPortion);
> > >> if (sizeof($arrDomainPortion) < 2) {
> > >> return false; // Not enough parts
> to domain
> > >> }
> > >> for ($i = 0, $max =
> sizeof($arrDomainPortion); $i <
> > >> $max; $i++) {
> > >> // Each portion must be between 1
> and 63
> > >> characters, inclusive
> > >> if (!$this-
> >check_text_length($arrDomainPortion
> > >> [$i], 1, 63)) {
> > >> return false;
> > >> }
> > >> if (!preg_match('/^(([A-Za-z0-9][A-

Blog Legend

unread,
Dec 7, 2008, 8:31:47 AM12/7/08
to php-email-addr...@googlegroups.com
Chris,

I highlighted, so you could find it quickly.  After cutting, and pasting snippets in different parts of the code,  I had to keep going up and down to check to make sure I included the entire code.  So to make it easier to find I highlighted it.  Hope it didn't throw you off too much.

I heard about the problem with your server, that sucks.  Hope you got it working...

Blog Legend

unread,
Dec 7, 2008, 8:46:23 AM12/7/08
to php-email-addr...@googlegroups.com
Franchesca,

Thank you for commenting,  I will play around with a few things today and see what happens.  I'm new at this too, so right now I'm sitting inside the airplane cockpit looking around at all the pretty lights and buttons hoping to find the ignition switch.
Bloglegend

Chris

unread,
Dec 7, 2008, 9:27:43 AM12/7/08
to php-email-addr...@googlegroups.com
OK, I'm finally online.  My copy of the page is at http://jesdisciple.110mb.com/EmailAddressValidator/test.php and it redirects as intended.  Here's the source.  (Note that you may need to combine some lines to make the comments work correctly because Google wraps them.)

<?php

$to = 'm...@mywebsite.com';

$header = $_POST['emailAddress'];
$subject = $_POST['inquiryOptions'];
$name = $_POST['fullName'];
$comment = $_POST['thoughts'];
$header = $_POST['emailAddress'];
$message = "From: $name\nSender e-mail address: $header\nRegarding:
$subject\n\nMessage:\n$comment\n";

if ($header =="") {
echo "<meta http-equiv=\"refresh\"
content=\"0;URL=error.html\">";
exit;
}
$success= mail($to, $subject, "From: <$header>");

if  ($success)
 {
     echo "<meta http-equiv=\"refresh\"
     content=\"0;Url=thankyou.php\">";
}
else
 {
echo "<meta http-equv=\"refresh\"
content=\"0;URL=failure.html\">";

}

   /*

       EmailAddressValidator Class
       http://code.google.com/p/php-email-address-validation/

       Released under New BSD license
       http://www.opensource.org/licenses/bsd-license.php

       Sample Code
       ----------------
       $validator = new EmailAddressValidator;
       if ($validator->check_email_address('te...@example.org')) {
?>


In ALL things, strive for ><>,
Chris


Blog Legend

unread,
Dec 7, 2008, 11:57:47 AM12/7/08
to php-email-addr...@googlegroups.com
Chris,

I'm not sure if the source is the code below, but I copied that one below and it errors at line 57 with this Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}'code line 57.  I also went to the link you provided, but it comes up as no longer there.  I'm still going through it to make sure I wasn't a victim of the cut and paste error from before, but so far haven't found it.

Chris

unread,
Dec 7, 2008, 1:31:13 PM12/7/08
to php-email-addr...@googlegroups.com
Line 57 is a line comment; make sure the line doesn't wrap around.  Or you could use a block comment instead, which would make line wraps irrelevant.

The page redirects to a page which doesn't exist; the page itself exists, and the redirection indicates that no error is encountered.

Chris

Chris

unread,
Dec 7, 2008, 1:35:50 PM12/7/08
to php-email-addr...@googlegroups.com
To clarify, in this context a line wrap is a newline placed where it shouldn't be by Google Groups (because it thinks a message consists purely of human language, which doesn't mind newlines).

Chris

Blog Legend

unread,
Dec 7, 2008, 1:57:36 PM12/7/08
to php-email-addr...@googlegroups.com
Chris,

Could you give me an example...how to wrap it, I used {} and tried eliminating that section of code all together, but none of it seemed to work for me.  I would be glad to reach that far in the sequence with the redirect link because that is a simple page error.  Instead I get stuck with parse error.  Right above the  public function check_email_address($
strEmailAddress) { string.  

David Child

unread,
Dec 7, 2008, 1:59:10 PM12/7/08
to php-email-addr...@googlegroups.com
Blog Legend, can you attach a zip containing your PHP file to your
next email please?

Chris

unread,
Dec 7, 2008, 2:31:26 PM12/7/08
to php-email-addr...@googlegroups.com
Dave (if that's your preferred name?), I didn't think the group would preserve an attachment?  Otherwise, I would have sent one myself.

I've updated my copy to output plain text rather than HTML, so it won't be redirecting anymore.  Also, appending ?action=source to the URL's end will display the PHP.


In ALL things, strive for ><>,
Chris


David Child

unread,
Dec 7, 2008, 2:35:53 PM12/7/08
to php-email-addr...@googlegroups.com
Dave is fine. I try to encourage the wife to use "Your Highness", but
for some reason that's not taken.

If the group will strip attachments out, perhaps uploading a zip to
the server would be useful - we're never going to be able to resolve a
line-wrapping issue (which is what it looks like at the moment) with
google getting in the way ...

Chris

unread,
Dec 7, 2008, 2:51:23 PM12/7/08
to php-email-addr...@googlegroups.com
Sorry Blog Legend, I forgot to respond to your last message.  As a block-to-line comment conversion example, this...

           // If magic quotes is "on", email addresses with quote marks will
           // fail validation because of added escape characters. Uncommenting
           // the next three lines will allow for this issue.
           //if (get_magic_quotes_gpc()) {
           //    $strEmailAddress = stripslashes($strEmailAddress);
           //}
would become this...
           /* If magic quotes is "on", email addresses with quote marks will

              fail validation because of added escape characters. Uncommenting
              the next three lines will allow for this issue.
             if (get_magic_quotes_gpc()) {
                $strEmailAddress = stripslashes($strEmailAddress);
             }*/

As for the error you cite, I haven't seen it for myself yet.  All the errors I've seen have been simple line wraps that left human language uncommented so the server tried to parse it as PHP.


In ALL things, strive for ><>,
Chris


Chris

unread,
Dec 7, 2008, 2:57:03 PM12/7/08
to php-email-addr...@googlegroups.com
I wasn't thinking straight...  That's line-to-block comment conversion.

Chris


...

[Message clipped]  

Blog Legend

unread,
Dec 7, 2008, 7:06:42 PM12/7/08
to php-email-addr...@googlegroups.com
Sorry Guys,

Had to go to work was away from my computer.  Chris I attempted to unwrap the file, but I would have to see an original to compare it too.    David, I sent a zip file with my code inside it.   I used microsoft works to create the file, so please let me know if it doesn't open.  If it doesn't I have the complete code listed in the group. 
Thanks again!


...

[Message clipped]  

validation.zip

Chris

unread,
Dec 7, 2008, 8:41:30 PM12/7/08
to php-email-addr...@googlegroups.com
I'm pleasantly surprised that uploads work.  :)

I don't understand why you converted block comments to line...  I said it that way once, but then corrected myself.  This change caused two extra errors, and the misalignment looks untidy.

Anyway, I modified your file as I did the other and uploaded it to http://jesdisciple.110mb.com/EmailAddressValidator/validation.php .  Add ?action=source for the PHP.  I encountered no error on Line 51; I'm beginning to suspect your PHP installation.


In ALL things, strive for ><>,
Chris


...

[Message clipped]  

Chris

unread,
Dec 7, 2008, 8:45:35 PM12/7/08
to php-email-addr...@googlegroups.com
Oh, and here's a wrapping example:
//This is a line
comment.

That would through an error because "comment" is outside the comment, which is terminated by the newline.  It's like writing
/*This is a block*/
comment.

These are the available fixes:
//This is a line comment.

/*This is a block
comment.*/

Chris


...

[Message clipped]  

Blog Legend

unread,
Dec 8, 2008, 5:49:19 AM12/8/08
to php-email-addr...@googlegroups.com
Chris,

Would it be possible for you to zip that file to me?  For some reason when I click the link provided below I get the redirect error.  Haven't been able to view the first modification that you provided, nor the second. 
<meta http-equiv="refresh"
content="0;URL=error.html">


I am working on my block conversion one day I won't make that mistake, but today I am humbled by your lesson.  ?action=source php where would you like me to add this to the script?  I'm using expression web, and have this script linked to the form via action, but if there is somewhere else on this php code itself you need me to add it I will definitely do so.

Besides that I wouldn't be surprised if after all of this cutting, pasting, and modifications it turns out to be the php installation.  Because that validation script looks very impressive.  I'm just a little skeptical because my original code works when testing without validation.  Once I able to view the code with all the new modifications I will plug it in, and test it.  If that doesn't work I will try reinstalling php, but for now I'm blaming google.
Good Morning...

 
...

[Message clipped]  

Chris

unread,
Dec 8, 2008, 8:51:21 AM12/8/08
to php-email-addr...@googlegroups.com
I zipped both files up and attached them.  But ?action=source should be appended to the URL, like so:
http://jesdisciple.110mb.com/EmailAddressValidator/validation.php?action=source


<meta http-equiv="refresh"
content="0;URL=error.html">
That's not an error but the script's output.  It displays as text because I instructed it to do so at the top of the PHP file.

Oh, and good morning.  :)  Our timezones must be close....


In ALL things, strive for ><>,
Chris


...

[Message clipped]  

tests.zip

Blog Legend

unread,
Dec 9, 2008, 5:51:33 AM12/9/08
to php-email-addr...@googlegroups.com
Chris,

I think I found the problem, give me about a day or two to figure out how expression web is parsing the code.  Question what version php are you using?

...

[Message clipped]  

Chris

unread,
Dec 9, 2008, 2:49:25 PM12/9/08
to php-email-addr...@googlegroups.com
Legend (for brevity),

I'm on PHP 5.1.6.  What's expression web?

Chris


...

[Message clipped]  

Franchesca Havas

unread,
Dec 9, 2008, 3:18:57 PM12/9/08
to php-email-addr...@googlegroups.com
It is what replaced the last real working version of frontpage.

It looks very similar to visual studio.

Franchesca Havas
from 3G

-----Original Message-----
From: Chris <jesdi...@gmail.com>
Sent: Tuesday, December 09, 2008 11:49 AM
To: php-email-addr...@googlegroups.com
Subject: Re: How do I...

Legend (for brevity),

I'm on PHP 5.1.6. What's expression web?

Chris


On Tue, Dec 9, 2008 at 7:21 AM, Blog Legend <blogl...@gmail.com> wrote:

> Chris,
>
> I think I found the problem, give me about a day or two to figure out how
> expression web is parsing the code. Question what version php are you
> using?
>
>
> On Mon, Dec 8, 2008 at 5:51 AM, Chris <jesdi...@gmail.com> wrote:
>
>> I zipped both files up and attached them. But ?action=source should be
>> appended to the URL, like so:
>>
>> http://jesdisciple.110mb.com/EmailAddressValidator/validation.php?action=source


[The entire original message is not included]

Blog Legend

unread,
Dec 10, 2008, 4:39:55 AM12/10/08
to php-email-addr...@googlegroups.com
Chris,

Expression web 2 actually is frontpage editor on steriods.  It is dreamweaver for microsoft in a nutshell.  I didn't get a chance to look at the code last night, but I'm going to take a look at it this morning.

...

[Message clipped]  

Blog Legend

unread,
Dec 10, 2008, 5:57:44 AM12/10/08
to php-email-addr...@googlegroups.com
Chris,

Quick update, I fixed the parse error.  You were correct in thinking that it might be the way how my server is handling the code.  It turns out that I was using 4.4.9 on my hosting site.  I went in updated it to php5 this morning, and the error went away.  I don't have time to do it right now, but tonight I have to go back and connect my error handling pages to match the added coding.  Quick question should I use the code from our previous discussion $validate ('header') to connect it?  Or is there something you can whip up to make this nightmare go away completely. 

Chris I have to really say thanks to you for sticking with me while I made changes Dave too for making a damn good code.
.
It is nice to join a group and not be bombarded with spam and other things that don't pertain to the topic. 
Bloglegend
Franchesca thank you too.

KS

unread,
Jan 5, 2009, 9:58:26 PM1/5/09
to php-email-address-validation
Hi everybody,

Excuse me if I am inappropriate in this group. I am really new to php
code. I have created a contact form including email address in Flash
actionscript 2.0 programming. I managed to check the a@y.c as a valid
email address. But obviously, that is not enough if you really would
like evaluate the validity of the real email address.

So, I am really excited when I saw this discussion page from google
search. I would like to learn the proper system of validating email
address using php code from experts like you.
Excuse me again if I ask a very basic and/or stupid question.

Can someone tell me how to use this final version of php code in flash
for a click event of the button?
I have used form.loadVariables("Contact_us.php", "POST"); Flash
actionscript syntax to send email with all the data entered by the
visitor considering a@y.c is a valid email address of the visitor. Can
I use similar kind of code to check email address validity using this
php code?

Thanks for your valuable time reading and giving your feedback.

-- KS --
> > On Sun, Dec 7, 2008 at 4:05 PM, David Child <d...@addedbytes.com> wrote:
>
> >> Dave is fine. I try to encourage the wife to use "Your Highness", but
> >> for some reason that's not taken.
>
> >> If the group will strip attachments out, perhaps uploading a zip to
> >> the server would be useful - we're never going to be able to resolve a
> >> line-wrapping issue (which is what it looks like at the moment) with
> >> google getting in the way ...
>
> >> On Sun, Dec 7, 2008 at 7:31 PM, Chris <jesdisci...@gmail.com> wrote:
> >> > Dave (if that's your preferred name?), I didn't think the group would
> >> > preserve an attachment?  Otherwise, I would have sent one myself.
>
> >> > I've updated my copy to output plain text rather than HTML, so it won't
> >> be
> >> > redirecting anymore.  Also, appending ?action=source to the URL's end
> >> will
> >> > display the PHP.
>
> >> > In ALL things, strive for ><>,
> >> > Chris
>
> >> > On Sun, Dec 7, 2008 at 3:29 PM, David Child <d...@addedbytes.com>
> >> wrote:
>
> >> >> Blog Legend, can you attach a zip containing your PHP file to your
> >> >> next email please?
>
> >> >> On Sun, Dec 7, 2008 at 6:57 PM, Blog Legend <blogleg...@gmail.com>
> >> wrote:
> >> >> > Chris,
>
> >> >> > Could you give me an example...how to wrap it, I used {} and tried
> >> >> > eliminating that section of code all together, but none of it seemed
> >> to
> >> >> > work
> >> >> > for me.  I would be glad to reach that far in the sequence with the
> >> >> > redirect
> >> >> > link because that is a simple page error.  Instead I get stuck with
> >> >> > parse
> >> >> > error.  Right above the  public function check_email_address($
> >> >> > strEmailAddress) { string.
>
> >> >> > On Sun, Dec 7, 2008 at 10:31 AM, Chris <jesdisci...@gmail.com>
> >> wrote:
>
> >> >> >> Line 57 is a line comment; make sure the line doesn't wrap around.
> >>  Or
> >> >> >> you
> >> >> >> could use a block comment instead, which would make line wraps
> >> >> >> irrelevant.
>
> >> >> >> The page redirects to a page which doesn't exist; the page itself
> >> >> >> exists,
> >> >> >> and the redirection indicates that no error is encountered.
>
> >> >> >> Chris
>
> >> >> >> On Sun, Dec 7, 2008 at 1:27 PM, Blog Legend <blogleg...@gmail.com>
> >> >> >> wrote:
>
> >> >> >>> Chris,
>
> >> >> >>> I'm not sure if the source is the code below, but I copied that one
> >> >> >>> below
> >> >> >>> and it errors at line 57 with this Parse error: syntax error,
> >> >> >>> unexpected
> >> >> >>> T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or
> >> '}'code
> >> >> >>> line
> >> >> >>> 57.  I also went to the link you provided, but it comes up as no
> >> >> >>> longer
> >> >> >>> there.  I'm still going through it to make sure I wasn't a victim
> >> of
> >> >> >>> the cut
> >> >> >>> and paste error from before, but so far haven't found it.
>
> >> >> >>> On Sun, Dec 7, 2008 at 6:27 AM, Chris <jesdisci...@gmail.com>
> >> wrote:
>
> >> >> >>>> OK, I'm finally online.  My copy of the page is at
> >> >> >>>>http://jesdisciple.110mb.com/EmailAddressValidator/test.phpand
> >> it
> >> >> >>>> redirects
> >> >> >>>> as intended.  Here's the source.  (Note that you may need to
> >> combine
> >> >> >>>> some
> >> >> >>>> lines to make the comments work correctly because Google wraps
> >> them.)
>
> >> >> >>>> <?php
>
> >> >> >>>> $to = '...@mywebsite.com';
> >> >> >>>> $header = $_POST['emailAddress'];
> >> >> >>>> $subject = $_POST['inquiryOptions'];
> >> >> >>>> $name = $_POST['fullName'];
> >> >> >>>> $comment = $_POST['thoughts'];
> >> >> >>>> $header = $_POST['emailAddress'];
> >> >> >>>> $message = "From: $name\nSender e-mail address:
> >> $header\nRegarding:
> >> >> >>>> $subject\n\nMessage:\n$comment\n";
>
> >> >> >>>> if ($header =="") {
> >> >> >>>> echo "<meta http-equiv=\"refresh\"
> >> >> >>>> content=\"0;URL=error.html\">";
> >> >> >>>> exit;
> >> >> >>>> }
> >> >> >>>> $success= mail($to, $subject, "From: <$header>");
>
> >> >> >>>> if  ($success)
> >> >> >>>>  {
> >> >> >>>>      echo "<meta http-equiv=\"refresh\"
> >> >> >>>>      content=\"0;Url=thankyou.php\">";
> >> >> >>>> }
> >> >> >>>> else
> >> >> >>>>  {
> >> >> >>>> echo "<meta http-equv=\"refresh\"
> >> >> >>>> content=\"0;URL=failure.html\">";
>
> >> >> >>>> }
>
> >> >> >>>>    /*
>
> >> >> >>>>        EmailAddressValidator Class
> >> >> >>>>        http://code.google.com/p/php-email-address-validation/
>
> >> >> >>>>        Released under New BSD license
> >> >> >>>>        http://www.opensource.org/licenses/bsd-license.php
>
> >> >> >>>>        Sample Code
> >> >> >>>>        ----------------
> >> >> >>>>        $validator = new EmailAddressValidator;
> >> >> >>>>        if ($validator->check_email_address('t...@example.org')) {
> >> >> >>>>            // Email address is technically valid
> >> >> >>>>        }
>
> >> >> >>>>    */
>
> ...
>
> read more »- Hide quoted text -
>
> - Show quoted text -

Chris

unread,
Jan 6, 2009, 3:39:47 AM1/6/09
to php-email-addr...@googlegroups.com
First, I need to apologize to Blog Legend.  I apparently didn't see your last message, or I simply forgot it.  Are you still reading?  Would it do any good for me to look into your question?

KS, I'm not familiar with ActionScript, although I have tried unsuccessfully to understand its API for haXe programming (to avoid paying for an Adobe license).  I'm guessing that the loadVariables method returns the output of the PHP page; if so, I see no reason that you couldn't validate an address in that manner.  Just test the value of the returned string according to your output pattern.

However, I cringe at the designation of me as an "expert."  I can't speak for David, but I'm just a hobbyist with a high school grounding in programming and loads of free education from online communities.  I plan to attend college to gain reinforcement and a degree for my hobby, but my help is "NOT INTENDED FOR USE IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL SYSTEMS, LIFE SUPPORT MACHINES OR OTHER EQUIPMENT IN WHICH THE FAILURE THEREOF  COULD LEAD TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE."  (That's almost straight from the GNU GPL.)


In ALL things, strive for ><>,
Chris


Cliff Cox

unread,
Jan 6, 2009, 7:07:51 AM1/6/09
to php-email-addr...@googlegroups.com
KS,
 
You can use this code to send and receive to and from php.
 
This is what I use, and it is solid.
 
Just put this code on a frame or in a function and call it from your button.
 
The ActionScript //////////////////////////////////////////////////////////////////////////////////
 
result_lv = undefined;

var result_lv:LoadVars = new LoadVars();
result_lv.onLoad = function(success:Boolean) {
 if (success) {

 // you get your values from the php file here.
 
trace (result_lv.validated);
// or
myVar = result_lv.validated;
// or
myStatus.text = result_lv.validated;
 
 // then do what you want to, or go where you want to go
 
gotoAndPlay(wherever);
     
 } else {

  // you catch you errors here if something went wrong
 
myStatus.text =  "Error connecting to server.";

 }
};
var send_lv:LoadVars = new LoadVars();
 
// you send what it is to be checked here

send_lv.emailAddress = e_mailAddress.text;
// or
send_lv.emailAddress = e_mailAddress;

send_lv.sendAndLoad("http://www.wherever/yourPHPfile.php", result_lv, "POST");

The PHP /////////////////////////////////////////////////////////////////////////////////////////////////
 
<?PHP
 
// Get information into php from Flash

$email = $_POST['emailAddress'];

// now you have a php variable with the flash value in it

// do what you have to do in php, then..

// Send it back to Flash

echo "&validated=true";

// the &validated is the flash variable

// the true is the value in it

?>

Make sure that after the above php close statement ( ?> ) you have nothing else, no extra characters or spaces otherwise you won't get a good value back in flash. In other words, when you close the php, nothing can be after it when communicating with flash.

It took me weeks to debug this and all I had was some invisible spaces following the close command, don't make the same mistake I did, It could drive you crazy.

 

Jnk

 

Reply all
Reply to author
Forward
0 new messages