I run a multi website and store setup, on PHP 7.1

I'm trying to import newsletter subscribers from a CSV as follows, which is in a CSV file called subscribers-import.csv in the root dir.

enter image description here

I'm using the following code in a file called import.php in the root dir.

use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$store_id = 1;
$csv_filepath = "subscribers-import.csv";
$csv_delimiter = ',';
$csv_enclosure = '"';
$magento_path = __DIR__;

$params = $_SERVER;

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

$obj = $bootstrap->getObjectManager();

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

$websiteId =  $obj->get('Magento\Store\Model\StoreManagerInterface')

$customerAccountManagement =$obj

$_subscriberFactory = $obj->create('Magento\Newsletter\Model\SubscriberFactory');

if (($handle = fopen("subscribers-import.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        // email Id
        $emailId =  $data[1];
       /* customer */
        if($customerAccountManagement->isEmailAvailable($emailId , $websiteId)){
            echo $emailId ."<br/>";
            $_subscriberFactory->create()->subscribe($emailId );
            echo $emailId ."Register <br/>";
            $customerFactory = $obj->get('Magento\Customer\Model\CustomerFactory');
            $customer->loadByEmail($emailId );// load customer by email address


Right now it only imports the email ID, as shown as follows.

enter image description here

How can I get it to import the rest of the data in the CSV like

Type | Customer First Name | Customer Last Name | Status | Website Store | Store View

1 Answer 1


Free Extension

You Got Value in $data Array Like This :-

$data[0] = id
$data[1] = email
$data[2] = type
$data[3] = customer first name
$data[4] = customer last name
$data[5] = status
$data[6] = website
$data[7] = store
$data[8] = store view

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.