How to get Newsletter Subscribers in Magento using Script?

Step: – 1
Using the Magento Admin panel we can download/export the CSV file but it can’t satisfy the client requirement means that Sometimes, our clients want only following Fields in Newsletter Subscriber CSV file.

Subscriber id, First name, Last name and Email Address

For those requirements we have to customize Newsletter Module but It is very risky for our Store because any small mistake will block the site. So that following is the simplest method for Download/Export the CSV file.

Step: – 2


ini_set('max_execution_time', 600);
ini_set('memory_limit', '1024M');

require 'app/Mage.php';
$app = Mage::app('');

$myFile = "var/export/subscribers.csv";
$fp = fopen($myFile, 'w');

$columns = array('customers_firstname','customers_lastname','customers_email_address');

/* get Newsletter Subscriber whose status is equal to "Subscribed"    */

$sql = "SELECT * FROM newsletter_subscriber WHERE subscriber_status = 1";
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
foreach ($connection->fetchAll($sql) as $arr_row) {

$loademail = $arr_row['subscriber_email'];

$customer = Mage::getModel('customer/customer');

$fname = explode(',', $customer->getData('firstname'));
$lname = explode(',', $customer->getData('lastname'));
$email = explode(',', $customer->getData('email'));
$fname = $fname[0];
$lname = $lname[0];
$email = $email[0];
if ($fname=="" && $lname=="")
$subscribers = array('firstname'=>$fname,'lastname'=>$lname,'email'=>$email);

header('Content-disposition: attachment; filename=' . $myFile);
header('Content-type: application/text');

Step: – 3 Just Copy above code and paste it into you PHP file and put that file into Root Directory of your Magento Store.

Step: – 4 After completion of above all the steps run your PHP file Manually.

For ex:-
Assume that you php file name is “Newsletter.php” and domain name of your magento store is “; then write following URL.

Step: – 5 Save the generated file.

Posted in Magento. 1 Comment »

One Response to “How to get Newsletter Subscribers in Magento using Script?”

  1. Says:

    Good day very nice site!! Guy .. Excellent ..
    Wonderful .. I’ll bookmark your blog and take the feeds also?
    I am glad to find numerous helpful info right here in the
    post, we need develop extra techniques on this regard, thanks for sharing.
    . . . . .

Speak Your Mind

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: