/    Sign up×
Community /Pin to ProfileBookmark

Validation email checker

Dear developer,

In order to check validation email address of email address text box, I’ve code the function as below. But unfortunately, it doesnt check the email (from) text box.

Here are my code…….

<?php

function check_email_address($email) {
// First, we check that there’s one @ symbol,
// and that the lengths are right.
if (!ereg(“^[^@]{1,64}@[^@]{1,255}$”, $email)) {
// Email invalid because wrong number of characters
// in one section or wrong number of @ symbols.
return false;
}
// Split it into sections to make life easier
$email_array = explode(“@”, $email);
$local_array = explode(“.”, $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++) {
if
(!ereg(“^(([A-Za-z0-9!#$%&’*+/=?^_`{|}~-][A-Za-z0-9!#$%&
&#8618;’*+/=?^_`
{|}~.-]{0,63})|(“[^(|”)]{0,62}”))$”,

$local_array[$i])) {
return false;
}
}
// Check if domain is IP. If not,
// it should be valid domain name
if (!ereg(“^[?[0-9.]+]?$”, $email_array[1])) {
$domain_array = explode(“.”, $email_array[1]);
if (sizeof($domain_array) < 2) {
return false; // Not enough parts to domain
}
for ($i = 0; $i < sizeof($domain_array); $i++) {
if
(!ereg(“^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|
&#8618;([A-Za-z0-9]+))$”,
$domain_array[$i])) {
return false;
}
}
}
return true;
}

$from = $_POST[“from”];
$subject = $_POST[“subject”];
$message = $_POST[“message”];
$header = “From: ” . $from . “rn”;

if(check_email_address($from))
{
if(empty($from))
{
echo “Error: Please Enter the Sender Email Address.”;
exit;
}
else
{
echo “Error: ‘$from’ is NOT a Valid Email Address.”;
exit;
}
}

$mailsent = mail(“[email protected]”, $subject, $message, $header);

if($mailsent)
{
echo “Congrats! The following message has been sent: <br><br>”;
echo “<b>To:</b> [email][email protected][/email]<br>”;
echo “<b>From:</b>$from<br>”;
echo “<b>Subject:</b> $subject<br>”;
echo “<b>Message:</b> $message<br>”;
echo $message;
}
else
{
echo “There was an error…”;
}

?>

Q : What’s wrong with these codes? Why it doesn’t check the valid email address in the from text box? Even I don’t type the email address in the from text box, it still sends the message to the reciever.

Cheers,
Visoth

to post a comment
PHP

1 Comments(s)

×

Success!

Help @phpian 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.9,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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