I develop a gateway module for magento 2 and when a customer who complete the registration process - i can get his email by :


but when i try to get a Guest email - i get a NULL value. There is a "Magento 2 way" to get it?

Javascript solution allready found: Magento2: How to get guest email address in checkout?

3 Answers 3


If we take a look: vendor/magento/module-checkout/Model/Type/Onepage.php

 protected function _prepareGuestQuote()
        $quote = $this->getQuote();
        return $this;

So, basically, we can get the guest email: $quote->getBillingAddress()->getEmail()

There are some other places:



  • Well detailed answer! i really like that you add some places at magento 2 build-in modules .
    – Goldy
    Commented Jul 11, 2016 at 19:17
  • did you find the solution
    – Jaisa
    Commented Jul 20, 2018 at 11:24
  • In case of the Guest customer, magento didn't map email id to shipping or billing address before place order.
  • In my case, I need guest email which is provided at the time of shipping page. To validate Guest email with Coupon code using this event ( salesrule_validator_process ) .

To Do that : Step 1: Create di.xml to override core code.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
  <preference for="Magento\Customer\Model\AccountManagement" type="Custom\Couponfriend\Model\AccountManagement" />

Step 2: Override model in custom module, and set email to
Quote's->shipping object. and get where you need it.


namespace Custom\Couponfriend\Model;

class AccountManagement extends \Magento\Customer\Model\AccountManagement {

    public function isEmailAvailable($customerEmail, $websiteId = null) {
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $cart = $objectManager->get('\Magento\Checkout\Model\Cart');
        $shippingAddress = $cart->getQuote()->getShippingAddress();

        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/guestFriendsFamily.log');
        $logger = new \Zend\Log\Logger();

        try {
            if ($shippingAddress) {
                $shippingAddress->setData('email', $customerEmail);
        } catch (NoSuchEntityException $e) {

        try {
            if ($websiteId === null) {
                $websiteId = $this->storeManager->getStore()->getWebsiteId();
            $this->customerRepository->get($customerEmail, $websiteId);
            return false;
        } catch (NoSuchEntityException $e) {
            return true;



You can override constructor to create cart object using dependency injection


This work for Magento 1

<?php class Exinent_Billingtax_Model_Observer { 
public function autoRegisterBilling($evt){
    $data =$evt->getEvent()->getControllerAction()->getRequest()->getPost('billing', array());
    echo "<pre>";
    $customer = Mage::getModel("customer/customer");
    $email = $data['email'];
    $websiteId = Mage::app()->getWebsite()->getId();
    $store = Mage::app()->getStore();
    $pwd = $data['customer_password'];

    if (!$customer->getId()) {
         //Code begins here for new customer registration
        $customer->website_id = $websiteId;
        $customer->firstname = $data['firstname'];
        $customer->lastname = $data['lastname'];
    Mage::getSingleton('customer/session')->loginById($customer->getId()); // to login that customer.


  • This doesn't answer the question which is about M2.
    – Aravona
    Commented Aug 1, 2019 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.