I have noticed that when exporting customer information through the admin panel it doesn't include all of the customers from the orders area.

I have been searching around for PHP code that does the job, although what I first need to understand is where I need to upload these PHP files for them to run successfully.

I am basically just wanting to export customer names and email addresses from the orders table so that I can import them into our email marketing application (and yes we do have permission to contact these people).

Do I need to upload PHP files to a specific folder in Magento for the queries to be able to access the data tables?

2 Answers 2


Just as long as you can get to the mage application from your script, it doesn't really matter where. Within reason of course - some will tell you to create a module in the local codebase, I prefer a "scripts" folder in the Magento root for simple data access. It depends on how involved you want to get with it.

In your script in the scripts folder, you can access the Application like so:


Once you have that, you can access the orders collection:

$orders = Mage::getModel('sales/order')->getCollection();

The reason you are not seeing all customers from orders is likely guest orders - if a customer checks out as a guest they are not saved in the list of customers.

  • Lovely stuff - thanks Ben. I have now been able to push on with this and create a PHP script that accesses the Sales Order table and writes all of the customer names and email addresses to a downloadable CSV file. I've password protected this PHP file for obvious reasons. If anyone would like me to post the code then please let me know and I'll be happy to do so. Thanks again - the Stack Exchange community are the best! Feb 4, 2014 at 18:25

As Ben already said, you can put them anywhere. We usually create a folder called tools for this kind of scripts which is located in the document root.

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.