Import newsletter subscribers (without sending any emails) into Magento

You can use the following script (the most important part is the “setImportMode(true)”, which will avoid the confirm emails to be sent):

<?php
 
$store_id = 5;
$csv_filepath = "newsletter.csv";
$email_csv_column_index = 2;
$csv_delimiter = ',';
$csv_enclosure = '"';
$magento_path = __DIR__;
 
require "{$magento_path}/app/Mage.php";
Mage::app()->setCurrentStore($store_id);
 
$fp = fopen($csv_filepath, "r");
if (!$fp) die("{$csv_filepath} not found\n");
while (($row = fgetcsv($fp, 0, $csv_delimiter, $csv_enclosure)) !== false) {
	$email = trim($row[$email_csv_column_index]);
	if (strlen($email) == 0) continue;
	echo "$email";
	
	$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
	if ($subscriber->getId()) {
		echo " already subscribed\n";
		continue;
	}
	
	Mage::getModel('newsletter/subscriber')->setImportMode(true)->subscribe($email);
	echo " ok\n";
}
 
echo "Import finished\n";

If you’re a github guy you can follow/star/fork this gist.

One thought on “Import newsletter subscribers (without sending any emails) into Magento

Leave a Reply

Your email address will not be published. Required fields are marked *