Get customer id by email address Magento 2.

You can get Customer id by customer email address using CustomerRepositoryInterface interface.

You can get Customer information by Customer email id, You need to use Magento\Customer\Api\CustomerRepositoryInterface to fetch customer id and customer data.

Simple Code stuff using Model,

<?php
/**
 * @author  Rakesh Jesadiya
 * @package Rbj_CustomerData
 */

namespace Rbj\CustomerData\Model;

use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Framework\Exception\NoSuchEntityException;

/**
 * Class Config
 */
class Config
{
    /**
     * @var CustomerRepositoryInterface
     */
    protected $customerRepository;

    public function __construct(
        CustomerRepositoryInterface $customerRepository
    ) {
        $this->customerRepository = $customerRepository;
    }

    /**
     * @param string $email
     * @return int|null
     */
    public function getCustomerIdByEmail(string $email)
    {
        $customerId = null;
        try {
            $customerData = $this->customerRepository->get($email);
            $customerId = (int)$customerData->getId();
        }catch (NoSuchEntityException $noSuchEntityException){
        }
        return $customerId;
    }

You need to call above function to get Customer id from Email id.

getCustomerIdByEmail($email) function need email id to fetch customer data.