Page 1 of 1

Help validating mail

Posted: Wed Jun 07, 2006 4:49 am
by mcoelho123
I have this code, but is returning the following error:

Warning: Missing argument 1 for checkemail() in D:\Domains\caselcoop.pt\wwwroot\tests\include\mail.php on line 2

Code: Select all

function checkEmail($from) { 
 if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/" , $from)){ 
  list($username,$domain)=split('@',$from); 
  if(!checkdnsrr($domain,'MX')) { 
   return false;
  } 
  return true; 
 } 
 return false; 
} 

if (checkEmail() == false){
  header("Location: " . "../sendmail.php?msg=notsent&send=" . $send);
}
the $from is working well if i make echo $from;

Posted: Wed Jun 07, 2006 4:55 am
by mcoelho123
the message is

Warning: Missing argument 1 for checkemail() in D:\Domains\caselcoop.pt\wwwroot\tests\include\mail.php on line 2

Warning: Cannot modify header information - headers already sent by (output started at D:\Domains\caselcoop.pt\wwwroot\tests\include\mail.php:2) in D:\Domains\caselcoop.pt\wwwroot\tests\include\mail.php on line 14

Why is not making the location:?

Posted: Wed Jun 07, 2006 5:35 am
by twigletmac
You have setup the checkEmail() function to have one parameter passed to it, you need to do this when you call the function, so keeping the function declaration as it is, change:

Code: Select all

if (checkEmail() == false) {
to

Code: Select all

if (checkEmail($from) == false) {
Mac

Re: Help validating mail

Posted: Wed Jun 07, 2006 5:37 am
by aerodromoi
mcoelho123 wrote:I have this code, but is returning the following error:

Warning: Missing argument 1 for checkemail() in D:\Domains\caselcoop.pt\wwwroot\tests\include\mail.php on line 2

Code: Select all

function checkEmail($from) { 
 if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/" , $from)){ 
  list($username,$domain)=split('@',$from); 
  if(!checkdnsrr($domain,'MX')) { 
   return false;
  } 
  return true; 
 } 
 return false; 
} 

if (checkEmail() == false){
  header("Location: " . "../sendmail.php?msg=notsent&send=" . $send);
}
the $from is working well if i make echo $from;
Looks like the function does not get fed properly ;) You'll have to call the function like this:

Code: Select all

checkEmail($from);
You'll have to check as well whether you echo something before calling the function (header problem).

btw 1: Your function will always return false - you'll have to include an else statement to make it work.
btw 2: A short version of your conditional statement:

Code: Select all

if (!checkEmail($from);)
aerodromoi

Posted: Wed Jun 07, 2006 5:41 am
by mcoelho123
OK, now it always redirect to the page its TRUE even i enter a valid email, whats wrong??

Posted: Wed Jun 07, 2006 5:42 am
by mcoelho123
sorry
i didnt change one of the funcion($from)

but now it gives me a error

Fatal error: Call to undefined function: checkdnsrr() in D:\Domains\caselcoop.pt\wwwroot\tests\include\mail.php on line 23

Posted: Wed Jun 07, 2006 5:43 am
by mcoelho123

Code: Select all

function checkEmail($from) {
 if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/" , $from)){
  list($username,$domain)=split('@',$from);
  if(!checkdnsrr($domain,'MX')) {
   return false;
  }
  return true;
 }
 return false;
}

if (checkEmail($from) == false){
  header("Location: " . "../sendmail.php?msg=notsent&send=" . $send);
}

if (checkEmail($from) == true){

Posted: Wed Jun 07, 2006 5:48 am
by twigletmac
Are you running on a Linux server or a Windows one because the manual says:
php.net/checkdnsrr wrote:This function is not implemented on Windows platforms. Try the PEAR class Net_DNS.
You also still need an else statement in that function (as aerodromoi pointed out) or it will always return false - plus to stop it always returning true if it passes the preg_match(), try:

Code: Select all

function checkEmail($from)
{
    if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/" , $from)){
        list($username,$domain)=split('@',$from);
        if(!checkdnsrr($domain,'MX')) {
            return false;
        } else {
            return true;
        }
    } else {
        return false;
    }
}
Mac

Posted: Wed Jun 07, 2006 5:53 am
by mcoelho123
Windows i think

If it is how can i do?

Posted: Wed Jun 07, 2006 5:54 am
by mcoelho123
yes it is
Windows NT HARPWRO-2 5.0 build 2195

How can i do, is there another way?

Posted: Wed Jun 07, 2006 5:55 am
by twigletmac
Check out the manual page for checkdnsrr() it gives a link to an alternative package.

Mac

Posted: Wed Jun 07, 2006 5:58 am
by mcoelho123
OK the webserver is not mine and i cant install anything (of course)
can u make a code that uses preg_match to check the mail?

Posted: Wed Jun 07, 2006 6:00 am
by mcoelho123
or this is enough

Code: Select all

preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/" , $from