Help validating mail

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mcoelho123
Forum Commoner
Posts: 37
Joined: Tue Jun 06, 2006 6:27 am

Help validating mail

Post 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;
Last edited by mcoelho123 on Wed Jun 07, 2006 5:02 am, edited 1 time in total.
mcoelho123
Forum Commoner
Posts: 37
Joined: Tue Jun 06, 2006 6:27 am

Post 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:?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Re: Help validating mail

Post 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
mcoelho123
Forum Commoner
Posts: 37
Joined: Tue Jun 06, 2006 6:27 am

Post by mcoelho123 »

OK, now it always redirect to the page its TRUE even i enter a valid email, whats wrong??
mcoelho123
Forum Commoner
Posts: 37
Joined: Tue Jun 06, 2006 6:27 am

Post 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
mcoelho123
Forum Commoner
Posts: 37
Joined: Tue Jun 06, 2006 6:27 am

Post 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){
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
mcoelho123
Forum Commoner
Posts: 37
Joined: Tue Jun 06, 2006 6:27 am

Post by mcoelho123 »

Windows i think

If it is how can i do?
mcoelho123
Forum Commoner
Posts: 37
Joined: Tue Jun 06, 2006 6:27 am

Post by mcoelho123 »

yes it is
Windows NT HARPWRO-2 5.0 build 2195

How can i do, is there another way?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Check out the manual page for checkdnsrr() it gives a link to an alternative package.

Mac
mcoelho123
Forum Commoner
Posts: 37
Joined: Tue Jun 06, 2006 6:27 am

Post 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?
mcoelho123
Forum Commoner
Posts: 37
Joined: Tue Jun 06, 2006 6:27 am

Post 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
Post Reply