Magento 2 - get user email IDMagento 2 Get customer ID from session in a block classget email id in email templateChange email logo for multistoreHow to get customer/guest user email address without using session in magentoMagento login not working properly with FPCGet customer email without sessionsGroup name from logged in userMagento 1.9 How to get Guest user id in CMS pages?Not able to sent the confirmation mail to the user?get Receiver's email-id in email header.html file magento2Magento 2: Login user programmatically showing wrong default header message “Default welcome msg!” instead of showing “Welcome, user!”

Giant Steps - Coltrane and Slonimsky

Why doesn't Adrian Toomes give up Spider-Man's identity?

Longest bridge/tunnel that can be cycled over/through?

Should I give professor gift at the beginning of my PhD?

How to use memset in c++?

How is John Wick 3 a 15 certificate?

Is this use of the expression "long past" correct?

Using "subway" as name for London Underground?

Geopandas and QGIS Calulating Different Polygon Area Values?

Did Milano or Benatar approve or comment on their namesake MCU ships?

Extreme flexible working hours: how to control people and activities?

Jargon request: "Canonical Form" of a word

Why we don’t make use of the t-distribution for constructing a confidence interval for a proportion?

You have (3^2 + 2^3 + 2^2) Guesses Left. Figure out the Last one

Certain search in list

Cascading Switches. Will it affect performance?

How does an ordinary object become radioactive?

Union with anonymous struct with flexible array member

How can I make some of my chapters "come to life"?

1980s live-action movie where individually-coloured nations on clouds fight

Tabular make widths equal

Does a scale have more than seven chords?

Arriving at the same result with the opposite hypotheses

How did old MS-DOS games utilize various graphic cards?



Magento 2 - get user email ID


Magento 2 Get customer ID from session in a block classget email id in email templateChange email logo for multistoreHow to get customer/guest user email address without using session in magentoMagento login not working properly with FPCGet customer email without sessionsGroup name from logged in userMagento 1.9 How to get Guest user id in CMS pages?Not able to sent the confirmation mail to the user?get Receiver's email-id in email header.html file magento2Magento 2: Login user programmatically showing wrong default header message “Default welcome msg!” instead of showing “Welcome, user!”






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I'm using Magento 2.2.6, How can I get the email ID of logged in user to show in header.



Thanks.










share|improve this question
























  • magento.stackexchange.com/questions/128830/… Please check link and if you replace getId() with getEmail(), you will get email of logged in customer.

    – Ramkishan Suthar
    Nov 7 '18 at 9:55












  • Is this for Email ID or User ID ?

    – user54226
    Nov 7 '18 at 10:02











  • You need to change getId() with getEmail() to get customer email. Here is one more example. blogtreat.com/get-logged-in-customer-data-in-magento-2

    – Ramkishan Suthar
    Nov 7 '18 at 10:10











  • @user54226 add below code

    – Balwant Singh
    Nov 21 '18 at 12:56

















1















I'm using Magento 2.2.6, How can I get the email ID of logged in user to show in header.



Thanks.










share|improve this question
























  • magento.stackexchange.com/questions/128830/… Please check link and if you replace getId() with getEmail(), you will get email of logged in customer.

    – Ramkishan Suthar
    Nov 7 '18 at 9:55












  • Is this for Email ID or User ID ?

    – user54226
    Nov 7 '18 at 10:02











  • You need to change getId() with getEmail() to get customer email. Here is one more example. blogtreat.com/get-logged-in-customer-data-in-magento-2

    – Ramkishan Suthar
    Nov 7 '18 at 10:10











  • @user54226 add below code

    – Balwant Singh
    Nov 21 '18 at 12:56













1












1








1








I'm using Magento 2.2.6, How can I get the email ID of logged in user to show in header.



Thanks.










share|improve this question
















I'm using Magento 2.2.6, How can I get the email ID of logged in user to show in header.



Thanks.







magento2 email customer-account magento2.2.6 customer-session






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 31 at 8:55









Kazim Noorani

1,1351824




1,1351824










asked Nov 7 '18 at 9:37









user54226user54226

416




416












  • magento.stackexchange.com/questions/128830/… Please check link and if you replace getId() with getEmail(), you will get email of logged in customer.

    – Ramkishan Suthar
    Nov 7 '18 at 9:55












  • Is this for Email ID or User ID ?

    – user54226
    Nov 7 '18 at 10:02











  • You need to change getId() with getEmail() to get customer email. Here is one more example. blogtreat.com/get-logged-in-customer-data-in-magento-2

    – Ramkishan Suthar
    Nov 7 '18 at 10:10











  • @user54226 add below code

    – Balwant Singh
    Nov 21 '18 at 12:56

















  • magento.stackexchange.com/questions/128830/… Please check link and if you replace getId() with getEmail(), you will get email of logged in customer.

    – Ramkishan Suthar
    Nov 7 '18 at 9:55












  • Is this for Email ID or User ID ?

    – user54226
    Nov 7 '18 at 10:02











  • You need to change getId() with getEmail() to get customer email. Here is one more example. blogtreat.com/get-logged-in-customer-data-in-magento-2

    – Ramkishan Suthar
    Nov 7 '18 at 10:10











  • @user54226 add below code

    – Balwant Singh
    Nov 21 '18 at 12:56
















magento.stackexchange.com/questions/128830/… Please check link and if you replace getId() with getEmail(), you will get email of logged in customer.

– Ramkishan Suthar
Nov 7 '18 at 9:55






magento.stackexchange.com/questions/128830/… Please check link and if you replace getId() with getEmail(), you will get email of logged in customer.

– Ramkishan Suthar
Nov 7 '18 at 9:55














Is this for Email ID or User ID ?

– user54226
Nov 7 '18 at 10:02





Is this for Email ID or User ID ?

– user54226
Nov 7 '18 at 10:02













You need to change getId() with getEmail() to get customer email. Here is one more example. blogtreat.com/get-logged-in-customer-data-in-magento-2

– Ramkishan Suthar
Nov 7 '18 at 10:10





You need to change getId() with getEmail() to get customer email. Here is one more example. blogtreat.com/get-logged-in-customer-data-in-magento-2

– Ramkishan Suthar
Nov 7 '18 at 10:10













@user54226 add below code

– Balwant Singh
Nov 21 '18 at 12:56





@user54226 add below code

– Balwant Singh
Nov 21 '18 at 12:56










2 Answers
2






active

oldest

votes


















1














First, create an instance in header.phtml file as below and also if more than one store is available and one wants to get mail in only one of the stores.



enter image description here



<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
$storeID = $storeManager->getStore()->getStoreId();
$storeName = $storeManager->getStore()->getName();
?>

<?php
$customerSession = $om->get('MagentoCustomerModelSession');
if($customerSession->isLoggedIn())
echo $customerSession->getCustomer()->getEmail(); // get Email

?>





share|improve this answer

























  • Thanks, and how can I place it below the customer name in customer-welcome element.

    – user54226
    Nov 22 '18 at 14:32











  • user54226 Answer edited.

    – SHEESHRAM
    May 31 at 8:12



















2














You need to inject MagentoCustomerModelSession $customerSession, class to get customer ID from customer session. Try this code.



protected $_customerSession;

public function __construct(
...
MagentoCustomerModelSession $customerSession,
...
)
...
$this->_customerSession = $customerSession;
...


public function getCustomer()

echo $this->_customerSession->getCustomer()->getId(); //Print current customer ID

$customerData = $this->_customerSession->getCustomer();
print_r($customerData->getData()); //Print current Customer Data
echo 'Customer Id: ' . $customerData->getId() . '<br/>';
echo 'Customer Name: ' . $customerData->getName() . '<br/>';
echo 'Customer Email: ' . $customerData->getEmail() . '<br/>';
echo 'Customer Group Id: ' . $customerData->getGroupId() . '<br/>';



NOTE: You only get customer id if customer logged in and customer session initialized






share|improve this answer























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f249277%2fmagento-2-get-user-email-id%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    First, create an instance in header.phtml file as below and also if more than one store is available and one wants to get mail in only one of the stores.



    enter image description here



    <?php
    $objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
    $storeID = $storeManager->getStore()->getStoreId();
    $storeName = $storeManager->getStore()->getName();
    ?>

    <?php
    $customerSession = $om->get('MagentoCustomerModelSession');
    if($customerSession->isLoggedIn())
    echo $customerSession->getCustomer()->getEmail(); // get Email

    ?>





    share|improve this answer

























    • Thanks, and how can I place it below the customer name in customer-welcome element.

      – user54226
      Nov 22 '18 at 14:32











    • user54226 Answer edited.

      – SHEESHRAM
      May 31 at 8:12
















    1














    First, create an instance in header.phtml file as below and also if more than one store is available and one wants to get mail in only one of the stores.



    enter image description here



    <?php
    $objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
    $storeID = $storeManager->getStore()->getStoreId();
    $storeName = $storeManager->getStore()->getName();
    ?>

    <?php
    $customerSession = $om->get('MagentoCustomerModelSession');
    if($customerSession->isLoggedIn())
    echo $customerSession->getCustomer()->getEmail(); // get Email

    ?>





    share|improve this answer

























    • Thanks, and how can I place it below the customer name in customer-welcome element.

      – user54226
      Nov 22 '18 at 14:32











    • user54226 Answer edited.

      – SHEESHRAM
      May 31 at 8:12














    1












    1








    1







    First, create an instance in header.phtml file as below and also if more than one store is available and one wants to get mail in only one of the stores.



    enter image description here



    <?php
    $objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
    $storeID = $storeManager->getStore()->getStoreId();
    $storeName = $storeManager->getStore()->getName();
    ?>

    <?php
    $customerSession = $om->get('MagentoCustomerModelSession');
    if($customerSession->isLoggedIn())
    echo $customerSession->getCustomer()->getEmail(); // get Email

    ?>





    share|improve this answer















    First, create an instance in header.phtml file as below and also if more than one store is available and one wants to get mail in only one of the stores.



    enter image description here



    <?php
    $objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
    $storeID = $storeManager->getStore()->getStoreId();
    $storeName = $storeManager->getStore()->getName();
    ?>

    <?php
    $customerSession = $om->get('MagentoCustomerModelSession');
    if($customerSession->isLoggedIn())
    echo $customerSession->getCustomer()->getEmail(); // get Email

    ?>






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited May 31 at 8:11

























    answered Nov 21 '18 at 12:56









    SHEESHRAMSHEESHRAM

    586




    586












    • Thanks, and how can I place it below the customer name in customer-welcome element.

      – user54226
      Nov 22 '18 at 14:32











    • user54226 Answer edited.

      – SHEESHRAM
      May 31 at 8:12


















    • Thanks, and how can I place it below the customer name in customer-welcome element.

      – user54226
      Nov 22 '18 at 14:32











    • user54226 Answer edited.

      – SHEESHRAM
      May 31 at 8:12

















    Thanks, and how can I place it below the customer name in customer-welcome element.

    – user54226
    Nov 22 '18 at 14:32





    Thanks, and how can I place it below the customer name in customer-welcome element.

    – user54226
    Nov 22 '18 at 14:32













    user54226 Answer edited.

    – SHEESHRAM
    May 31 at 8:12






    user54226 Answer edited.

    – SHEESHRAM
    May 31 at 8:12














    2














    You need to inject MagentoCustomerModelSession $customerSession, class to get customer ID from customer session. Try this code.



    protected $_customerSession;

    public function __construct(
    ...
    MagentoCustomerModelSession $customerSession,
    ...
    )
    ...
    $this->_customerSession = $customerSession;
    ...


    public function getCustomer()

    echo $this->_customerSession->getCustomer()->getId(); //Print current customer ID

    $customerData = $this->_customerSession->getCustomer();
    print_r($customerData->getData()); //Print current Customer Data
    echo 'Customer Id: ' . $customerData->getId() . '<br/>';
    echo 'Customer Name: ' . $customerData->getName() . '<br/>';
    echo 'Customer Email: ' . $customerData->getEmail() . '<br/>';
    echo 'Customer Group Id: ' . $customerData->getGroupId() . '<br/>';



    NOTE: You only get customer id if customer logged in and customer session initialized






    share|improve this answer



























      2














      You need to inject MagentoCustomerModelSession $customerSession, class to get customer ID from customer session. Try this code.



      protected $_customerSession;

      public function __construct(
      ...
      MagentoCustomerModelSession $customerSession,
      ...
      )
      ...
      $this->_customerSession = $customerSession;
      ...


      public function getCustomer()

      echo $this->_customerSession->getCustomer()->getId(); //Print current customer ID

      $customerData = $this->_customerSession->getCustomer();
      print_r($customerData->getData()); //Print current Customer Data
      echo 'Customer Id: ' . $customerData->getId() . '<br/>';
      echo 'Customer Name: ' . $customerData->getName() . '<br/>';
      echo 'Customer Email: ' . $customerData->getEmail() . '<br/>';
      echo 'Customer Group Id: ' . $customerData->getGroupId() . '<br/>';



      NOTE: You only get customer id if customer logged in and customer session initialized






      share|improve this answer

























        2












        2








        2







        You need to inject MagentoCustomerModelSession $customerSession, class to get customer ID from customer session. Try this code.



        protected $_customerSession;

        public function __construct(
        ...
        MagentoCustomerModelSession $customerSession,
        ...
        )
        ...
        $this->_customerSession = $customerSession;
        ...


        public function getCustomer()

        echo $this->_customerSession->getCustomer()->getId(); //Print current customer ID

        $customerData = $this->_customerSession->getCustomer();
        print_r($customerData->getData()); //Print current Customer Data
        echo 'Customer Id: ' . $customerData->getId() . '<br/>';
        echo 'Customer Name: ' . $customerData->getName() . '<br/>';
        echo 'Customer Email: ' . $customerData->getEmail() . '<br/>';
        echo 'Customer Group Id: ' . $customerData->getGroupId() . '<br/>';



        NOTE: You only get customer id if customer logged in and customer session initialized






        share|improve this answer













        You need to inject MagentoCustomerModelSession $customerSession, class to get customer ID from customer session. Try this code.



        protected $_customerSession;

        public function __construct(
        ...
        MagentoCustomerModelSession $customerSession,
        ...
        )
        ...
        $this->_customerSession = $customerSession;
        ...


        public function getCustomer()

        echo $this->_customerSession->getCustomer()->getId(); //Print current customer ID

        $customerData = $this->_customerSession->getCustomer();
        print_r($customerData->getData()); //Print current Customer Data
        echo 'Customer Id: ' . $customerData->getId() . '<br/>';
        echo 'Customer Name: ' . $customerData->getName() . '<br/>';
        echo 'Customer Email: ' . $customerData->getEmail() . '<br/>';
        echo 'Customer Group Id: ' . $customerData->getGroupId() . '<br/>';



        NOTE: You only get customer id if customer logged in and customer session initialized







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 12:53









        Balwant SinghBalwant Singh

        3991316




        3991316



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f249277%2fmagento-2-get-user-email-id%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form