4

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.

3

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

<?php
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');
$state->setAreaCode('frontend');

$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, privacy policy and cookie policy

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