It is necessary to come up with an algorithm that would be from such an array
array(3) { [0]=> array(2) { ["forms_email"]=> "max@gmail.com, sm@yandex.ru.ru" ["form_name"]=> "form_compl" } [1]=> array(2) { ["forms_email"]=> "max@gmail.com, 123@da.fwe" ["form_name"]=> "TESTED" } [2]=> array(2) { ["forms_email"]=> "sm@yandex.ru" ["form_name"]=> "formname2" } } would do this:
array(3) { [0]=> array(2) { ["forms_email"]=> "max@gmail.com" ["form_name"]=> "form_compl, TESTED" } [1]=> array(2) { ["forms_email"]=> "123@da.fwe" ["form_name"]=> "TESTED" } [2]=> array(2) { ["forms_email"]=> "sm@yandex.ru" ["form_name"]=> "formname2, form_compl" } } that is, for each e-mail you need to specify everything ["form_name"] where there is a match. this is done to send letters, ["form_name"] - the names of the files, then an array will be made of them and will go as an attachment to the letter, therefore, this is the kind needed. array size can be any, as well as the number of recipients