0

I have a 2D array such as the below:

Array ( 
[0] => Array ( 
     [asin] => B004HFS6Z0 
     [title] => Kindle, Wi-Fi, Graphite, 6" Display with New E Ink Pearl Technology - includes Special Offers & Sponsored Screensavers 
     [price] => 114.00 
     [map] => 125.00 
     [email] => [email protected] ) 
[1] => Array ( 
     [asin] => B004CYX17O 
     [title] => Rizzy Home Apple 10-Piece Comforter Set, King 
     [price] => 502.80 
     [map] => 520.00 
     [email] => [email protected] ) ) 

What I want to do with it is export it into 2 csv files (could be more) based on the email field and then email the csv file as an attachment to the email address in the field. There would be multiples with the email address that I would want to all be in the same csv file but when the email is different I would want that in a seperate csv file.

Is this possible? I am not sure where to begin with this but would really like some suggestions! Thanks in advance!

2
  • So, just to be clear: you want to send one mail per email address? Commented Jun 19, 2011 at 18:12
  • Yes that's correct. One email per address that would have mulitple items from the array. Commented Jun 19, 2011 at 18:14

1 Answer 1

1

Yes its possible. Look at fopen, fputcsv and tempnam to write the csv data to a temp file.

The easiest way to send attachments is to use PEAR Mail library or Zend_Mail. You could write it yourself, but it does take a bit of work.

Sign up to request clarification or add additional context in comments.

4 Comments

I've used fputcsv to create a csv file but how could I sperate the array based on the email field? That's really where I am stuck. Thanks for your help.
Rebuild your array and add a new dimension with the email address. Then look through that array and write a csv and send an email for each loop.
OK. I've got the new array built with the email as the main key. Could you give me an example of how to loop thru it to write a seperate csv per email?
Look the array using foreach and assign both the key and value. Open a temp file for the csv data and then look through the subarray to write the csv data. Generate the email and attach the temp file to the email as an attachment. Using Zend_Mail or Pear mail is the easiest way to do this. Best to refer to the documentation for examples.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.