Click to See Complete Forum and Search --> : Newbie email from web page


digital_storm
01-26-2006, 04:24 PM
Hello!

I'm new to php and have a question about sending mail from a webbpage.

I know that I can use syntax like:
<?php
.
.
.
$headers="From: $emailfrom";
mail($to, $subject, $message, $headers);
?>

to send mail but this syntax doesnt take care about "fake emailadresses" so you can write what you want as $emailfrom

I have tried to do like
<?php
if(mail($to, $subject, $message, $headers);)...
?>

but this doesnt either work....

Is there a way to control that $emailfrom is a working emailadress?

Regards /D_S

LiLcRaZyFuZzY
01-26-2006, 04:33 PM
you'd have to check the $emailfrom variable and test it against a RegEx (Regular Expression)

something like that:
/^[-^!#$%&'*+\/=?`{|}~.\w]+@[a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9])*(\.[a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9])*)+$/

in PHP:

$pattern = "/^[-^!#$%&'*+\/=?`{|}~.\w]+@[a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9])*(\.[a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9])*)+$/";
if(preg_match($pattern, $emailfrom)){
# e-mail address should be valid
}else{
# e-mail address will most probably not be valid
}


i've read somewhere that this pattern would cover all e-mail addresses according to some specifications, but i'm not sure of that..

digital_storm
01-26-2006, 04:38 PM
Thanks!

Your example covers the "syntax" but is there a way to control if given emailadress is existing? When you write an invalid http url you get an error message that says that current url doesnt exist. Is there a way to control if an email is existing?

Regards/D_S

LiLcRaZyFuZzY
01-26-2006, 04:40 PM
yes there is, it's a bit more complicated.
this article will help: http://www.zend.com/zend/spotlight/ev12apr.php

digital_storm
01-26-2006, 05:25 PM
Thanks!

I'll try that...

Regards/D_S