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
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.