2

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

1
  • Are you sure there are any subscribers in the first place?
    – mbalparda
    Commented Dec 29, 2014 at 14:37

3 Answers 3

4

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.

1
  1. Check in the magento backend for the site that there are actual subscribers.
  2. Are you loading the required magento file at app/Mage.php?
  3. 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(); } }

0

This is a more efficient way to do it:

$newsletterSubscribers = Mage::getResourceModel('newsletter/subscriber_collection')
        ->addFieldToFilter('subscriber_status', array ('eq' => 1)); // 1 is subscribed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.