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 = '[email protected]';
$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 you have read our privacy policy.

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