---
title: "How to Add Newsletter Subscriber Programmatically in Magento 2?"
url: "https://magecomp.com/blog/add-newsletter-subscriber-programmatically-magento-2/"
date: "2023-03-20T12:35:45+00:00"
modified: "2025-02-14T06:06:05+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 287
reading_time: "2 min read"
summary: "Hello Magento Friends,"
description: "To Add Newsletter Subscriber Programmatically in Magento 2, create a Data.php file inside the Helper folder. Find out more"
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Create Custom Require JS File in Magento 2?"
    url: "https://magecomp.com/blog/create-custom-require-js-file-magento-2/"
  - title: "A Complete Guide on Keeping Magento 2 Store Maintained/Up to Date"
    url: "https://magecomp.com/blog/complete-guide-on-keeping-magento-2-store-maintained/"
  - title: "How to Remove Image Magnifier &#038; Slider in Magento 2 Product Page"
    url: "https://magecomp.com/blog/remove-image-magnifier-slider-in-magento-2-product-page/"
---

# How to Add Newsletter Subscriber Programmatically in Magento 2?

_Published: March 20, 2023_  
_Author: Dhiren Vasoya_  

![How to Add Newsletter Subscriber Programmatically in Magento 2](https://magecomp.com/blog/wp-content/uploads/2023/03/How-to-Add-Newsletter-Subscriber-Programmatically-in-Magento-2-1024x512.webp)

**Hello Magento Friends,**

In today’s blog, we will learn about How to Add Newsletter Subscriber Programmatically in Magento 2?
[![Magento Malware Removal](https://magecomp.com/blog/wp-content/uploads/2023/04/Magento-Malware-Removal-CTA-1.webp)](https://magecomp.com/magento-malware-removal.html)

A newsletter helps to build relationships with customers. It is an important aspect of the email marketing strategy of an eCommerce business. Learn [**How to Grow Newsletter Subscribers**](https://magecomp.com/blog/how-to-grow-newsletter-subscribers/).
Magento 2 store owners can easily [**create newsletters**](https://magecomp.com/blog/create-and-manage-newsletters-in-magento-2/) and [**manage subscribers**](https://magecomp.com/blog/manage-newsletter-subscribers-report-in-magento-2/) using the admin panel. Moreover, [**Newsletter Popup**](https://magecomp.com/magento-2-newsletter-popup.html) helps to catch users’ attention and increase the newsletter subscribers list.
You have an email of customers, and you want to add them to the newsletter subscriber list. You can achieve it programmatically in Magento 2. Let’s learn How to Add Newsletter Subscriber Programmatically in Magento 2.
## Steps to Add Newsletter Subscriber Programmatically in Magento 2:
**Step 1:** Create a **Data.php** file inside the Helper folder
**app\code\Vendor\Extension\Helper**

Then add the code as follows
```
<?php
namespace VendorExtensionHelper;
use MagentoStoreModelStoreManagerInterface;
use MagentoFrameworkAppHelperAbstractHelper;

class Data extends AbstractHelper
{
   protected $subscriberFactory;

   public function __construct(
         MagentoNewsletterModelSubscriberFactory $subscriberFactory
         )
   {
       $this->_subscriberFactory = $subscriberFactory;
   }

   public function setNewslettersubscriber()
   {
      $customeremail = 'test.magecomp@gmail.com';
      $subscriber = $this->_subscriberFactory->create()->loadByEmail($customeremail);
      $subscriber->setStatus(MagentoNewsletterModelSubscriber::STATUS_UNSUBSCRIBED);
      $subscriber->save();
   }
}
```

[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-1.webp)](https://magecomp.com/magento-performance-optimization.html)

You can initialize the object, Magento\Newsletter\Model\SubscriberFactory, to add a subscriber in block, controller etc. You can also add the subscriber by any email ID.

## Conclusion:
This way, you can add newsletter subscribers programmatically in Magento 2. Admin can [**send Newsletters Manually to Customer Group**](https://magecomp.com/blog/send-newsletters-manually-to-customer-group-in-magento-2/) in Magento 2. If you have difficulty adding the newsletter subscriber, contact me through comments for the solution.
Share the tutorial with your friends on social media and stay in the know for the latest updates.
[![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-1.webp)](https://magecomp.com/services/hyva-theme-development/)

**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/add-newsletter-subscriber-programmatically-magento-2/](https://magecomp.com/blog/add-newsletter-subscriber-programmatically-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-07-15 18:35:47 UTC_  
