1

I used Magento 2.2.4 Version.

Magento2 How to Get Newsletter Subscribed Collection into phtml file

2

Not recommended way:

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
$subscriberCollection = $objectManager->create('Magento\Newsletter\Model\ResourceModel\Subscriber\Collection');

foreach($subscriberCollection as $subscriber):
   print_r($subscriber->getData());
endforeach;

Recommended way:

protected $subscriberCollection;

public function __construct(
    \Magento\Newsletter\Model\ResourceModel\Subscriber\CollectionFactory $subscriberCollectiona
) {
    $this->subscriberCollection = $subscriberCollection;
}

public function getSubscriberCollection() {
    $subscriberCollection =$this->subscriberCollection->create();
    return $subscriberCollection;
}

In phtml:

$subscriberCollection = $block->getSubscriberCollection();
foreach($subscriberCollection as $subscriber):
    print_r($subscriber->getData());
endforeach;
1
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$newsletterCollectionFactory = $objectManager->get('\Magento\Newsletter\Model\ResourceModel\Subscriber\CollectionFactory');
$collection = $newsletterCollectionFactory->create();

foreach ($collection as $product) {
    print_r($product->getData());
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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