Html form simple validation

Hi,

when I have a simple single line form only for collecting emails -> What's the best way to validate this email and then send it through PHP to client's email?

I searched many sites but as a newbie in this field it gets confusing which approach is actually the right. So any ideas or links please.
LVL 1
Fajer39Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SSupremeCommented:
This tutorial here: http://www.w3schools.com/php/php_form_url_email.asp
In previous steps you can see why and how to make basic validation using pure PHP and even remove exploits.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fajer39Author Commented:
Thanks SSupreme.
0
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

Ray PaseurCommented:
Just stumbled across this Q&A and I think it deserves a better answer.  Using a REGEX to validate an email address is the sort of thing we might have done a decade ago - nobody does something like that any more.  Today we use the built-in PHP filters.  Here are the links to the relevant man pages.
http://php.net/manual/en/function.filter-var.php
http://php.net/manual/en/filter.filters.validate.php
http://php.net/manual/en/filter.filters.sanitize.php

This Q&A brings up two issues that deserve attention.  First, check the age of sources and references.  Many things on the W3Schools site are still useful, but this is not one of them.  It's literally several years out of date!  Please don't propagate obsolete code examples when there are modern solutions we can choose instead.

Second, to Fajer39, you might want to consider leaving your E-E questions open for at least 24 hours.  The E-E community is all volunteers, and we often do not see questions immediately (some of us check in at the end of the workday, for example).  If you leave the questions open for a day, you will undoubtedly get many more sets of eyes on the problem!
0
SSupremeCommented:
Ray, I cannot see any newer information provided from your links compared to mine.  "filter_var" exist since 2006 when 5.2 was released and even if W3Schools out of date, may be you have your own up to date resource?!

Ray, you can say that REGEX was used by dinosaurs but http://php.net/manual/ru/function.preg-match.php still exists and if you want live validation you would probably use REGEX.

Please don't spread false information, to confuse author.
0
Ray PaseurCommented:
If you feel that any part of the information I shared is "false" please point it out, thanks.
0
SSupremeCommented:
Today we use the built-in PHP filters
from link provided by me http://www.w3schools.com/php/php_form_url_email.asp you can see following:
$email = test_input($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  $emailErr = "Invalid email format";
}

Open in new window

Clear usage example of PHP filter for email as requested in question.
Yet, you state:
Many things on the W3Schools site are still useful, but this is not one of them.  It's literally several years out of date!
, it is a contradiction.
Using a REGEX to validate an email address is the sort of thing we might have done a decade ago - nobody does something like that any more.
Completely wrong statement! Gmail still use, for example, I guess, when somebody typed wrong symbol at registration, it suggests: (see image), how? REGEX! NOT PHP filter!  Also you can google for live validation, and most of the time is REGEX.
And the video about REGEX from EE submitted on 2014-08-12 and updated in May this year. All of that means, at least some people still use it.

More over, personally, I would never suggest using PHP filter for email acceptance because it stops correct emails to system, at the end of the day, humans know better what they want to writer and system can provide a hint or make an attention.
Capture.JPG
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.