Can anyone tell me the php code to import Newsletter subscribers into M2? I have thousands of subscribers I'd like to import but don't know enough php to do it without a guide.

1 Answer 1


Add below code to any file and put that file in magento root

use Magento\Framework\App\Bootstrap;

require __DIR__ . '/app/bootstrap.php';

$params = $_SERVER;

$bootstrap = Bootstrap::create(BP, $params);

$obj = $bootstrap->getObjectManager();

$state = $obj->get('Magento\Framework\App\State');

$email = 'test@gmail.com';
$status = $obj->get('Magento\Newsletter\Model\Subscriber')->subscribe($email);


You need to add code according to your csv.

Your Answer

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

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