I'm running into the following problem: I have a list of emails in a file. I want to loop through these and create customers, then I want to do something with the customer. However in my script it's only loading the last customer.
I have the following code:
require_once("./app/Mage.php");
Mage::app();
$file = fopen("Test.txt", "r");
if ($file) {
$emails = file("Test.txt");
foreach($emails as $email) {
echo $email . "<br/>"; // < shows all emails
// load up the customer
$customer = Mage::getModel('customer/customer')
->setWebsiteId(1)
->loadByEmail($email);
echo $customer->getId() . "<br/>"; // < returns blank except for the last email line
// if we found the customer
if ($customer->getId()){
echo $customer->getId() . "adsf<br/>"; // < only shown on last line
//.. do something
}
}
fclose($file);
} else {
// error opening the file.
}
I have also tried
while(!feof($file)){
$email = fgets($file);
and
while (($email = fgets($file)) !== false)
but same result, so it appears it's not something wrong with the php code. Can someone help me?