Running a multi website and store setup. Example Website - Japan Store - JP Store View - JP I'm trying to import newsletter subscribers from a CSV. I'm using the following code in a file called **import.php** that I run from the root dir. eg: dev.xyz.com/import.php and the subscribers.csv is also in the root dir. <?php use Magento\Framework\App\Bootstrap; require __DIR__ . '/app/bootstrap.php'; $store_id = 1; $csv_filepath = "subscribers.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'); $state->setAreaCode('frontend'); $websiteId = $obj->get('Magento\Store\Model\StoreManagerInterface') ->getStore() ->getWebsiteId(); $customerAccountManagement =$obj ->create('Magento\Customer\Api\AccountManagementInterface'); $_subscriberFactory = $obj->create('Magento\Newsletter\Model\SubscriberFactory'); if (($handle = fopen("subscribers.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { // email Id $emailId = $data[0]; /* customer */ if($customerAccountManagement->isEmailAvailable($emailId , $websiteId)){ echo $emailId ."Guest <br/>"; $_subscriberFactory = $_subscriberFactory->create()->subscribe($emailId ); }else{ echo $emailId ."Register <br/>"; $customerFactory = $obj->get('Magento\Customer\Model\CustomerFactory'); $customer=$customerFactory->create(); $customer->setWebsiteId($websiteId); $customer->loadByEmail($emailId );// load customer by email address if($customer->getId()){ $_subscriberFactory->create()->subscribeCustomerById($customer->getId()); } } } fclose($handle); } CSV Headers/Column names as follows: **ID | Email | Type | Customer First Name | Customer Last Name | Status | Website Store | Store View** But I get the following error IDGuest Warning: Cannot modify header information - headers already sent by (output started at /home/xyz/dev.xyz.com/import.php:36) in /home/xyz/dev.xyz.com/vendor/magento/framework/Stdlib/Cookie/PhpCookieManager.php on line 148 Fatal error: Uncaught Magento\Framework\Stdlib\Cookie\FailureToSendException: The cookie with "mage-cache-sessid" cookieName couldn't be deleted. in /home/xyz/dev.xyz.com/vendor/magento/framework/Stdlib/Cookie/PhpCookieManager.php:154 Stack trace: #0 /home/xyz/dev.xyz.com/vendor/magento/framework/Stdlib/Cookie/PhpCookieManager.php(301): Magento\Framework\Stdlib\Cookie\PhpCookieManager->setCookie('mage-cache-sess...', '', Array) #1 /home/xyz/dev.xyz.com/vendor/magento/module-customer/CustomerData/Plugin/SessionChecker.php(54): Magento\Framework\Stdlib\Cookie\PhpCookieManager->deleteCookie('mage-cache-sess...', Object(Magento\Framework\Stdlib\Cookie\CookieMetadata)) #2 /home/xyz/dev.xyz.com/vendor/magento/framework/Interception/Interceptor.php(121): Magento\Customer\CustomerData\Plugin\SessionChecker->beforeStart(Object(Magento\Framework\Session\Generic\Interceptor)) #3 /home/xyz/dev.xyz.com/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\Sessio in /home/xyz/dev.xyz.com/vendor/magento/framework/Stdlib/Cookie/PhpCookieManager.php on line 154 How can I import newsletter subscribers from a CSV? Thanks in advance. ----------------------- UPDATE ----------------------- Changed code as suggested by Rajesh Hothi Now I get the following error IDGuest Fatal error: Uncaught Exception: The input is not a valid email address. Use the basic format local-part@hostname in /home/xyz/dev.xyz.com/vendor/magento/module-newsletter/Model/Subscriber.php:501 Stack trace: #0 /home/xyz/dev.xyz.com/import.php(37): Magento\Newsletter\Model\Subscriber->subscribe('ID') #1 {main} thrown in /home/xyz/dev.xyz.com/vendor/magento/module-newsletter/Model/Subscriber.php on line 501 Format of CSV file shown below. [![enter image description here][1]][1] It imports one line in which the email ID doesn't show and its not in the order of the csv file, as below. [![enter image description here][2]][2] [1]: https://i.sstatic.net/W6VRB.png [2]: https://i.sstatic.net/WiICZ.png