if mail() function

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
revathy
Forum Newbie
Posts: 11
Joined: Sun Jul 12, 2009 11:18 pm

if mail() function

Post 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... :roll:

Thanks in advance,
Revathy.
User avatar
sanju
Forum Commoner
Posts: 65
Joined: Sat Jun 21, 2008 2:15 am
Location: Kochi, India

Re: if mail() function

Post by sanju »

hi

Chk email domains using php functions like checkdnsrr() before sending mail using mail function.

Regards
Sanj
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: if mail() function

Post 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.
revathy
Forum Newbie
Posts: 11
Joined: Sun Jul 12, 2009 11:18 pm

Re: if mail() function

Post 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.
User avatar
sanju
Forum Commoner
Posts: 65
Joined: Sat Jun 21, 2008 2:15 am
Location: Kochi, India

Re: if mail() function

Post by sanju »

it wont work with improper mail ids . This functions check if the domains are valid or not....

Regards
revathy
Forum Newbie
Posts: 11
Joined: Sun Jul 12, 2009 11:18 pm

Re: if mail() function

Post by revathy »

Is there any other possible solutions for my problem sanj.

-Revathy.
User avatar
sanju
Forum Commoner
Posts: 65
Joined: Sat Jun 21, 2008 2:15 am
Location: Kochi, India

Re: if mail() function

Post by sanju »

Actually you need not proper mail-id,s to work???
revathy
Forum Newbie
Posts: 11
Joined: Sun Jul 12, 2009 11:18 pm

Re: if mail() function

Post 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.
User avatar
sanju
Forum Commoner
Posts: 65
Joined: Sat Jun 21, 2008 2:15 am
Location: Kochi, India

Re: if mail() function

Post 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.
revathy
Forum Newbie
Posts: 11
Joined: Sun Jul 12, 2009 11:18 pm

Re: if mail() function

Post by revathy »

Ok thank you sanju, I will try to do this by using checkdnsrr().

Thanks,
Revathy.
Post Reply