How to get the customer email address in Magento

I was recently working on a payment module for Magento and I needed to fetch the customer email address to submit it along with the other payment details.

I found a method by which I could get the email of the customer who was already registered on the website and was shopping after logging in with his/her details.

$cusemail = Mage::getSingleton('customer/session')->getCustomer()->getEmail();

However the above line returned empty in case of a first time customer. So I modified the code as follows

$cusemail = Mage::getSingleton('customer/session')->getCustomer()->getEmail();

if (strlen($cusemail) > 0) {
	// Do nothing
}
else {
	//Get the current order details in a $order variable and fetch the customer email from there 
	$cusemail = $order['customer_email'];	
}

Hope the above helped.

Leave a Reply

Your email address will not be published. Required fields are marked *