Another Undefined Variable

I have this code but I get :Notice: Undefined variable: CustomerEmail

<?php 
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
   $customer = Mage::getSingleton('customer/session')->getCustomer();
   $CustomerEmail = $customer->getEmail();
}
$pageIdentifier = Mage::app()->getFrontController()->getAction()->getFullActionName();
?>
<?php if ($CustomerEmail != ''): ?>  <-- Undefined variable: CustomerEmail

I don’t understand because this variable seems to be defined above with $CustomerEmail = $customer->getEmail();

How can I fix this?

Thank you

$CustomerEmail is only defined within the brackets following the if statement. Something called scope. All you need to do is to initialize it outside of the brackets.

<?php
$CustomerEmail = '';
if (Mage:: ....

And where did you come across this Mage framework? Seems a bit dated to say the least.

I would have added isset($CustomerEmail) && to ensure the variable has been set and is not empty.

1 Like

I think that fixed it.

That framework is Magento. eCommerce.

Thanks!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.