TM-GNM Posted January 19, 2022 Share Posted January 19, 2022 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 Quote Link to comment https://forums.phpfreaks.com/topic/314433-sending-multiple-attachments-from-databases/ Share on other sites More sharing options...
ginerjm Posted January 19, 2022 Share Posted January 19, 2022 Do you have some php code to show us how far you are? Do use the <> icon for the code when you post it here. Quote Link to comment https://forums.phpfreaks.com/topic/314433-sending-multiple-attachments-from-databases/#findComment-1593462 Share on other sites More sharing options...
mac_gyver Posted January 19, 2022 Share Posted January 19, 2022 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. 1 Quote Link to comment https://forums.phpfreaks.com/topic/314433-sending-multiple-attachments-from-databases/#findComment-1593465 Share on other sites More sharing options...
TM-GNM Posted January 20, 2022 Author Share Posted January 20, 2022 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. Quote Link to comment https://forums.phpfreaks.com/topic/314433-sending-multiple-attachments-from-databases/#findComment-1593484 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.