Page 1 of 1
if mail() function
Posted: Sun Jul 12, 2009 11:34 pm
by revathy
Hi, I want Email validation code in PHP. For this, I used "if mail()" function in php.
But my code always returns true if I give the mail id like this,
a@a.com.
I need if the mail sent successfully without failure notice then only it will do the true part, otherwise it goes to false part. But my code do the true part and sent failure notice to the "From address". Can anyone know solution for this, please help me. Its very urgent...
Thanks in advance,
Revathy.
Re: if mail() function
Posted: Mon Jul 13, 2009 12:27 am
by sanju
hi
Chk email domains using php functions like checkdnsrr() before sending mail using mail function.
Regards
Sanj
Re: if mail() function
Posted: Mon Jul 13, 2009 12:39 am
by Eric!
the mail() function returns true anytime you call it with the correct number of parameters. It doesn't care if those parameters produce a valid email or not.
Try using the new filter_var in php 5.2.0+
Code: Select all
<?php
if(!filter_var("someone@example...com", FILTER_VALIDATE_EMAIL))
{
echo("E-mail is not valid");
}
else
{
echo("E-mail is valid");
}?>
http://www.php.net/filter_var
It doesn't do domain checking, but it's better than nothing. You could also use a regex filter, there are a ton of examples on the net.
Re: if mail() function
Posted: Mon Jul 13, 2009 12:43 am
by revathy
Thank you for your kind reply sanj. Is it possible to work with while i give a most improper mail id (ie., if i give fake email id's) like this,
gsdfjhgs@shfgs.sdyfgs
-Revathy.
Re: if mail() function
Posted: Mon Jul 13, 2009 12:51 am
by sanju
it wont work with improper mail ids . This functions check if the domains are valid or not....
Regards
Re: if mail() function
Posted: Mon Jul 13, 2009 1:15 am
by revathy
Is there any other possible solutions for my problem sanj.
-Revathy.
Re: if mail() function
Posted: Mon Jul 13, 2009 2:16 am
by sanju
Actually you need not proper mail-id,s to work???
Re: if mail() function
Posted: Mon Jul 13, 2009 3:15 am
by revathy
Hi sanj, If i give mail id
revathyelan@yahoo.com then it should send a mail to that ID and download a file which was I uploaded already in my site. If i give mail id like this,
asdjga@ashdg.cgaksd, then it show an error msg "Invalid mail id". For this I used the php code
$user =$Email;
$sub = "Hai";
$content = "You are registered in our site";
if(mail($user, $sub, $content))
{
header('.../files/'.$filename);
}
else
{
echo "Invalid Mail ID";
}
But it always download my file. If I give
revathyelan@yahoo.com then it sent an appropriate mail for me. No problem in that. But if tried by using "
asfdgha@asdj.casydgui",
something like this, then also it downloads my file. I want to avoid the second type of user to download my file.
Re: if mail() function
Posted: Mon Jul 13, 2009 4:17 am
by sanju
Thats What I have already said to you validate your mail id before using it. That is "$user =$Email; " You should validate $Email before using it. For that you can use domain validation functions that I have already mentioned . Mail function will always return true . It will not bother about the email-id.
Re: if mail() function
Posted: Mon Jul 13, 2009 5:17 am
by revathy
Ok thank you sanju, I will try to do this by using checkdnsrr().
Thanks,
Revathy.