I'm trying to get newsletter subscribers using the code:
$subscribers = Mage::getModel('newsletter/subscriber')->getCollection();
but it is empty. Where I'm wrong? thanks
This will show last 10 newsletter subscribers:
$collection = Mage::getModel('newsletter/subscriber')->getCollection()
->setPageSize(10)
->setOrder('subscriber_id', 'desc');
foreach ($collection as $subscriber) {
Zend_Debug::dump($subscriber->getData());
}
Look at Mage_Newsletter_Model_Resource_Subscriber_Collection
to see which methods are available. Also look at newsletter_subscriber
table.
app/Mage.php
?Are you looping over the items in that collection somehow? You'll probably need to do a foreach loop on it like this:
foreach ($subscribers as $subscriber){
if ($subscriber->getSubscriberStatus()){
// Do something with $subscriber->getSubscriberEmail();
}
}
This is a more efficient way to do it:
$newsletterSubscribers = Mage::getResourceModel('newsletter/subscriber_collection')
->addFieldToFilter('subscriber_status', array ('eq' => 1)); // 1 is subscribed