/    Sign up×
Community /Pin to ProfileBookmark

Newbie email from web page

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

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYJan 26.2006 — you'd have to check the $emailfrom variable and test it against a RegEx ([B]Reg[/B]ular [B]Ex[/B]pression)

something like that:
[CODE]/^[-^!#$%&'*+/=?{|}~.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])*)+$/[/CODE]</CODE>

in PHP:
<CODE lang="php">[code=php]<i>
</i> $pattern = "/^[-^!#$%&amp;'*+/=?
{|}~.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
}
[/code]


i've read somewhere that this pattern would cover all e-mail addresses according to some specifications, but i'm not sure of that..
Copy linkTweet thisAlerts:
@digital_stormauthorJan 26.2006 — 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
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYJan 26.2006 — yes there is, it's a bit more complicated.

this article will help: http://www.zend.com/zend/spotlight/ev12apr.php
Copy linkTweet thisAlerts:
@digital_stormauthorJan 26.2006 — Thanks!

I'll try that...

Regards/D_S
×

Success!

Help @digital_storm spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...