I’m currently using the Simplenews Drupal module for creating and sending newsletters. My client requested that the subscriber export function be changed to export all subscriber details to CSV. As the export option already retrieves all subscriber emails and generates a comma seperated string, exporting to CSV only requires a few extra lines of php.
After the following piece of code:
// Build form field containing exported emails.
// The field will be included in the form where at the ['emails'] place holder.
if (isset($mails)) {
$exported_mails = implode(", ", $mails);
}
else {
$exported_mails = t('No addresses were found.');
}
Add the following:
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=subscribers.csv");
print $exported_mails;
exit;
Easy!
Thanks a lot for the example. I was getting problem with the csv export. It was exporting all the page content along with the subscribers mail information. Your examples last line "exit" saved lot of time of mine. Thanks Again
Brillant !!
worked like a charm :)
… just need to specify that you have to edit the “simplenews.admin.inc” not “simplenews.module” ;)
Thanks chocspread, I’m glad to hear this still works as it’s been a while since this post was written :)
Thanks Bro for wonderful post.
Googled for how to export & your post came up, Fired Up the code & worked wonders..
Thanks Again.
Sorry, Sister..!!
In case someone who does not want to add codes to contrib module can add another submit callback to the form by hook_form_alter.
In submit callback function they can call _simplenews_subscription_list_export_get_emails() to get the csv data in order to get csv file.
Thanks for article. :)
— Jeet.
Perfect! Thanks!
Hey! I just wanted to ask if you ever have any issues with hackers?
My last blog (wordpress) was hacked and I ended up losing several weeks of hard work due to no backup.
Do you have any methods to prevent hackers?