Jump to content

sending multiple attachments from databases


TM-GNM

Recommended Posts

Hi! A ex-staffer  created a functions file that emails to me, as attachments, CSV files of 21 elists in the MySQL databases of multiple websites. It creates one email per CSV file. I'd like to changed the code to send multiple files per email. (So can I save them in my computer by save-all instead of one at a time.)

I've attached the current code. Instead of 21 separate emails, I'd like just 4, divided like so:

'website-subscribers' should include 3 attachments:
                                    'media',
                                    '30days',
                                    'footsteps',

‘dada' should include these attachments:
                'blessings',
                'booknews',
                'dailyreflections',
                'earlydr',
                'eastdr',
                'notify',
                'eclass',
                'prayernetwork',
                'reflexiones',
                'saints',
                'sundays',

'download-link-users' should include these attachments:
                                                '30days',
                                                'footsteps',
                                                'gnm',
                                                'es',
                                                'media',
                                                'wb',

'7warriors' should be sent by itself.


Please help! I'm in over my head. Thank you!

email functions file.txt

Link to comment
Share on other sites

change the code to use arrays for the sets of data under each major category, rather than processing each list/site separately. write two new functions (keeping the old code as is.) the new add_all_subscribers_lists_array() function would build arrays of parameters inside the inner foreach() loop, then call a new add_subscriber_list_array() function once, after the end of the inner foreach() loop. the code in the new add_subscriber_list_array() function would loop over the arrays of input parameters, query for the data and build each .csv file, then call the wp_mail() function once, supplying an array of the attachments.

of some concern is that the code is creating a new database connection for each list/site. are all these databases on the same database server, with the only difference being which database is selected? if so, the code only needs to select the database before each query, rather than create an entirely new connection for each list/site query.

for the 7warriors .csv, the posted code only outputs three headings, but there are four columns of data. to fix this, you would define a specific $column_names array inside the 7warriors conditional logic.

  • Thanks 1
Link to comment
Share on other sites

15 hours ago, mac_gyver said:

change the code to use arrays for the sets of data under each major category, rather than processing each list/site separately. write two new functions (keeping the old code as is.) the new add_all_subscribers_lists_array() function would build arrays of parameters inside the inner foreach() loop, then call a new add_subscriber_list_array() function once, after the end of the inner foreach() loop. the code in the new add_subscriber_list_array() function would loop over the arrays of input parameters, query for the data and build each .csv file, then call the wp_mail() function once, supplying an array of the attachments.

of some concern is that the code is creating a new database connection for each list/site. are all these databases on the same database server, with the only difference being which database is selected? if so, the code only needs to select the database before each query, rather than create an entirely new connection for each list/site query.

for the 7warriors .csv, the posted code only outputs three headings, but there are four columns of data. to fix this, you would define a specific $column_names array inside the 7warriors conditional logic.

Thank you. They are all on the same server -- different websites but same server.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.