Jump to content

[SOLVED] Checking Submit & Validating an Email w/ Global Vars On :: Cannot Resolve


programguru

Recommended Posts

Hello,

 

I am working on a script which has been kicking my butt long hours into the night, and I just wanted to see if any one had any input on what I am doing wrong.

First off, my script is a "simple" mail script, and all I am trying to do is:

 

1) Test when the Submit button is clicked (but this seems to happen when the pages loads every time!!!_.

2) Next, test the entered email address for validity with a homemade function.

3) Send the email if the submit is true (pushed) and the email tests to TRUE. Note: isset() did not work for this (unless I was using it wrongly).

 

The issues I am having is:

 

1) Page loads with email message "Sent..." or "Bad Email..." even if the Submit is not clicked. Meaning I either get one or the other with all of my experimenting, but all I want is the correct message to load after the Submit is clicked.

 

Here are the applicable snippets of my code:

 

The main validation function:

 

function checkEmail($email) 

{
   if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) 
   {
      return FALSE;
   }

   list($Username, $Domain) = split("@",$email);

   if(@getmxrr($Domain, $MXHost)) 
   {
      return TRUE;
   }
   else 
   {
      if(@fsockopen($Domain, 25, $errno, $errstr, 30)) 
      {
         return TRUE; 
      }
      else 
      {
         return FALSE; 
      }
   }
}

 

The Code for the actual script (one of many variations):

 

if ($_GET['true'] AND checkEmail($email) == FALSE) {

echo "<div align=\"center\" class=\"thankyou\">";
echo "Please enter a valid email address!";
echo "</div>";

}

else { 

 

[b]... mail() code is here ...[/b]

	echo "<div align=\"center\" class=\"thankyou\">";
echo "Thank you! Your request has been submitted.";
echo "</div>";

}

 

 

Note:

 

1) My <form is tagged with "true" like:

<form action="<?php echo $_SERVER['PHP_SELF']; ?>?submit=true" method="get">
- this is to test the "true".

 

I've been up all night attempting variations of the if statement and testing the value of true, but nothing seems to work.

 

I figure I just need an external eye to spot my stupid problem!

 

Any ideas?

 

Link to comment
Share on other sites

Although I mentioned above, I just want to clarify the problem I cannot get around:

 

My messages: "Please enter a valid email address!" and "Thank you! Your request has been submitted." load when the page loads.

 

From all of my testing, this is the main issue I cannot get around (testing if elsif variations etc..)

 

I must be doing something really dumb to not be able to solve this, but I just can't see straight any longer....

Link to comment
Share on other sites

From the description of the symptoms, the logic tests in your code are either non-existent or incorrect. There is no way anyone in a Forum will be able to specifically help you with what your code is doing unless you post all of it.

 

If by "Global Vars On" you mean register_globals, DON'T write any code that is dependent on register_globals being on. They were turned off in 2002 and no new code should have been written after that point in time that used them. They have been completely removed in upcoming php6.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.