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

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

            Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

            Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?