Validating and verifying email addresses in PHP

Поделиться
HTML-код
  • Опубликовано: 14 июн 2024
  • email validation API: ► davehollingworth.com/go/email...
    PHP for Beginners course: ➤ davehollingworth.net/phpy
    PHP MVC course: ► davehollingworth.net/phpmvcy
    CodeIgniter 4 course: ► davehollingworth.net/codeigni...
    Often in a PHP web application or website we need a user to provide an email address, for example when they sign up for an account, fill in an order form and so on. How do we make sure the user has entered a valid email address using PHP? One that's a valid format, but also one that isn't fake?
    In addition to checking the format, email verification checks whether an email address is accurate, valid, and deliverable. We can check for disposable email addresses, free email addresses and more.
    Verifying email addresses will make sure emails you send out will avoid spam filters and keep bounce rates low.
    Resources:
    www.php.net/manual/en/functio...
    www.php.net/manual/en/book.cu...
    www.abstractapi.com/email-ver...
    Code shown in the video:
    gist.github.com/daveh/833577a...
    00:00 Introduction
    00:58 Validate format
    03:00 email validation API
    08:26 Examples
    10:04 Summary
    #PHP #email #API
  • НаукаНаука

Комментарии • 45

  • @NedumEze
    @NedumEze 3 года назад +1

    Wow! How helpful! And far simpler and smaller than the one I, which has to send a test mail to surfer to validate, which he cannot do, if address is fake.
    Thanks again, Dave

  • @ignaciomontali
    @ignaciomontali 2 года назад +2

    Great tutorials! Ive seen a few and the rythm simplifies the content plus the organization and the step by step progress! Thank you very much! I´m Already subscribed!

  • @antonioserafimovski7398
    @antonioserafimovski7398 3 года назад +1

    You are awesome man i learned so much from ur videos thanks a lot!

  • @jooryalhamed938
    @jooryalhamed938 2 года назад +1

    Many thanks, this has worked perfectly!

  • @saviorpascal6323
    @saviorpascal6323 2 года назад

    a very big thank you to you for helping me solve one of yet my biggest problem

  • @nbvdib2098
    @nbvdib2098 2 года назад

    thx man, you just saved me in 1:52 minutes

  • @danieligbinidu6880
    @danieligbinidu6880 Год назад +1

    Thanks alot for help

  • @RagHelen
    @RagHelen 2 года назад

    I am tempted to try this service with a fresh address, just to see, if I get any spam after that :) But the video is very nice to watch.

  • @abujoha1555
    @abujoha1555 Год назад +1

    Nice Brother.

  • @IBeThieving
    @IBeThieving 3 года назад +3

    One other thing I like to do is validate the existence of the email address domain by sending a request to that domain. This reduces strain on the database should a user use a fake email and also allows you to not rely on 3rd party API’s more of an in house solution to reduce costs. Great video though!

    • @dave-hollingworth
      @dave-hollingworth  3 года назад +1

      Totally agree - when I do a registration site, I require users to confirm their email address by sending them a unique token contained in a URL, denying them login until they have confirmed the email address. Glad you like the video!

    • @IBeThieving
      @IBeThieving 3 года назад

      @@dave-hollingworth Absolutely combining the two creates a very robust solution.

    • @NedumEze
      @NedumEze Год назад

      Could you share the code you use to query the domain here, please?

  • @deepatripathi7829
    @deepatripathi7829 2 года назад +1

    thank you

  • @ramsesramos1151
    @ramsesramos1151 Год назад +1

    It works! thank you so much Dave!, a noob question.. how can i display the result messages on top of the input inside form.html instead of them showing on the validate_email.php? again thank you so much

    • @dave-hollingworth
      @dave-hollingworth  Год назад

      You'd have to either redirect back to the original page, passing the error message back to that page somehow - for example in the query string or in the session. Alternatively you could process the submitted form in the same script as the HTML at the top, then redisplay the form if there are errors.

  • @DavidAshby1
    @DavidAshby1 Год назад

    Great video. I have been doing a little research regarding email addresses and sanitization as well as validation. As usual, there are a variety of opinions regarding email addresses. Some say, sanitize the email address before you do anything else with it, some say validate before sanitize. Keeping in mind, if the field is required, and html5 automatically looks for a correct format and then getting the end user to verify their account, as I think you mention in a reply below, before they can log in and then have a script that scrubs the database of unverified accounts after, say 24hrs, is that enough or would you recommend a 3rd party API to also check the email address does actually exist?

    • @dave-hollingworth
      @dave-hollingworth  Год назад

      It depends on how much work you want your script to do - if you use a third-party API to check that the email address actually exists, then you'll save yourself trying to send an email to a non-existent address (something you might want if you're paying for the number of emails you send)

    • @DavidAshby1
      @DavidAshby1 Год назад

      @@dave-hollingworth Trying to identify role email addresses but no matter what I do it does not identify them.
      I have
      elseif($data['is_role_email'] === true){
      echo "Role Email";
      }
      This is a continuation from your code. I am assuming that the code I have written here is wrong but unsure. Could you possibly advise? Thanks

    • @DavidAshby1
      @DavidAshby1 Год назад

      Think I have it
      if($data['is_role_email']["value"] === false){
      echo "Role Email";
      }

  • @akhwatjomblochannel789
    @akhwatjomblochannel789 Год назад

    can i use password gmail from API ? what solution ? thanks

  • @jamestrey3049
    @jamestrey3049 8 месяцев назад +1

    excuse me! Can I use justValidation as the script language to display the api email result in the html file or need Ajax to process them? is there any solution that no need to get the next page to verify mail log up? please help me

    • @dave-hollingworth
      @dave-hollingworth  8 месяцев назад +1

      Yes, if you want to use Ajax to get the result of validating the email on the server, that's no problem

    • @jamestrey3049
      @jamestrey3049 8 месяцев назад +1

      @@dave-hollingworth tks sir

    • @jamestrey3049
      @jamestrey3049 8 месяцев назад

      @@dave-hollingworth How can I use JustValidate to display them sir

    • @dave-hollingworth
      @dave-hollingworth  8 месяцев назад

      @@jamestrey3049 Check out this example in the documentation: just-validate.dev/examples#async-validation

    • @jamestrey3049
      @jamestrey3049 8 месяцев назад

      Thanks Dave!@@dave-hollingworth I also have a question How to create email register in the log up

  • @victorpaulson5712
    @victorpaulson5712 10 месяцев назад +1

    Great video! How can check up to 10 emails at once without having to input them one after the other ? Thanks

    • @dave-hollingworth
      @dave-hollingworth  10 месяцев назад

      If you put them in an array you can loop around that array and check each one at once

    • @victorpaulson5712
      @victorpaulson5712 10 месяцев назад

      @@dave-hollingworth Thanks. Well I successfully typed in both the html code and php code but I got this error..
      Warning: Undefined array key “deliverability”
      Warning: Undefined array key “is_disposable_email”
      Warning: Trying to access array offset on value of type null

    • @dave-hollingworth
      @dave-hollingworth  10 месяцев назад

      @@victorpaulson5712 Without seeing the code that these error messages refer to, it's a bit difficult to debug - try posting the relevant code snippet here or in pastebin or somewhere similar

    • @victorpaulson5712
      @victorpaulson5712 10 месяцев назад

      @@dave-hollingworth do you mean I should post the full codes here or what, I’m sorry I didn’t really get what you meant. Also I think I got lost in the video when you brought it the Curl part, I didn’t really understand what you did there 🤷🏼‍♂️ could it be because I didn’t use the Curl ?

    • @dave-hollingworth
      @dave-hollingworth  10 месяцев назад

      @@victorpaulson5712 Yes, I meant post the code that's causing the error so I can see if I can spot the problem. It could be because you're not using cURL but it's not clear from the error message.

  • @sheriwatson9055
    @sheriwatson9055 2 года назад

    I've tried this and it's not working quite right. I copied and pasted the code into the appropriate files. The html works fine. I can input a real working email and the page is returned blank. I'm not getting the data dump. I included the $var_dump($data); line and it is still not working.

    • @dave-hollingworth
      @dave-hollingworth  2 года назад

      A blank screen usually means an error is occurring, but PHP isn't configured to display them. Try adding these lines to the top of your script:
      ini_set('display_errors', '1');
      ini_set('display_startup_errors', '1');
      error_reporting(E_ALL);

    • @penaldocubeg9516
      @penaldocubeg9516 9 месяцев назад

      It is showing the .php page code when I entered a valid email. Not getting the output please help

  • @malikzain601
    @malikzain601 2 года назад

    How many bulk emails we can valid in an hour?

    • @dave-hollingworth
      @dave-hollingworth  2 года назад

      www.abstractapi.com/email-verification-validation-api#pricing

    • @kraleemil
      @kraleemil 2 года назад

      79 i think

  • @AbdulAlim-gv1gs
    @AbdulAlim-gv1gs Год назад

    Hello, what is your contact email?