Programatically check customer email exist in magento

Programatically check customer email exist in magento (tested in v 1.5.1.0)



<?php
require_once 'app/Mage.php';
umask(0);
$websiteId = Mage::app()->getWebsite()->getId();
$email = 'ajzele@someserver123.com';// Your Customers Email Here

function IscustomerEmailExists($email, $websiteId = null){
    $customer = Mage::getModel('customer/customer');

    if ($websiteId) {
        $customer->setWebsiteId($websiteId);
    }
    $customer->loadByEmail($email);
    if ($customer->getId()) {
        return $customer->getId();
    }
    return false;
}

$cust_exist = IscustomerEmailExists($email,$websiteId);

if($cust_exist){
    echo "Customer Email Exists Already. And your Customer id is <b>'".$cust_exist."'</b>";
}
else{
     echo "Customer Email <b>'".$email."'</b> Not Exists : So you Need to Enter All data like shipping info ,billing info";
}
?>

Thanks to : http://svn.magentocommerce.com/source/branches/1.2/app/code/core/Mage/Checkout/Model/Type/Onepage.php

Share on Facebook