Magento 2 Get Customer's Telephone after registration

Magento 2 Get Customer's Telephone after registration

August 6, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 2 Get Customer's Telephone after registration

Accessing Customer Address Information in Magento 2 Activation Emails

As a beginner in Magento 2 development, you’re right on track trying to include customer address information in your admin activation emails. In this guide, I’ll help you understand why the current code isn’t working and provide a step-by-step solution.

Why Your Current Code Isn’t Working

The issue lies in how Magento 2 manages customer addresses. When you create or register a new customer, their primary shipping address is not attached to them by default. You need to assign this address to the customer before you can access it in your code.

Here’s how the relationship works:

  • A customer entity
  • Can have multiple addresses
  • Only one of these addresses is set as the “default” or primary shipping address

Your current code attempts to get the address directly from the customer object, which fails because no default address is assigned yet.

Accessing Customer Address Information

To solve this, you need to ensure a default address is assigned to your customer and then access it correctly. Here’s how:

  1. Assign a Default Shipping Address

After creating or editing a customer, make sure you assign their primary shipping address using the setIsDefaultShipping method on the address object.

$address = $customer->getAddressesCollection()->getFirstItem();
$address->setIsDefaultShipping(true);
$address->save();
  1. Access Customer Address Information

Now that a default address is set, you can access its details correctly:

// Get the first (primary) shipping address for the customer
$address = $customer->getAddressesCollection()->getFirstItem();

// Access the address attributes
$company = $address->getCompany();
$telephone = $address->getTelephone();
$street = implode(', ', $address->getStreet()); // Combine street lines into one string

// Set these as template variables for your email
$this->setTemplateVars([
    // ... other customer data ...
    'company' => $company,
    'telephone' => $telephone,
    'address' => $street,
]);

Remember to replace // ... other customer data ... with the existing customer information you’re already setting.

Conclusion

In Magento 2, accessing customer address information requires careful handling of the relationship between customers and addresses. Always ensure a default shipping address is assigned before trying to access its details in your code.

By following this approach, you’ll be able to successfully include customer company name, telephone number, and address in your admin activation emails or any other part of your Magento 2 application.

For more advanced Magento 2 development techniques like working with custom attributes and extending core functionality, I recommend checking out the official Magento documentation and resources available at Laravel Company.

Happy coding!

Magento 2 Admin Email Customers

Our network