1 (edited by bobloblian 12/03/2021 10:16:59 pm)

Topic: emailing multiple contacts

Hi Folks,

I have taken it upon myself to migrate into a new instance of FA for my next fiscal year.  Nothing particularly wrong with my existing instance, just did all of my learning in there and want a fresh database. 

Way back when I first started using FA I reported an email problem:


so now in my fresh install with only a minimal amount of setup done, I am seeing that this problem is still present where it only sends to the first contact in the list.

It was never confirmed absolutely in the above mentioned post if anyone can actually successfully send to multiple recipients with out messing with the code, so I would start by asking if anyone can do that?  It would be very unexpected that I am the only one who needs or wants to use this feature, but maybe it is the case?

Assuming a negative answer, I am just going through the basics:

*As per @Apmuthu's suggestion in the above mentioned post, I have changed the last parameter of line 138 of reporting/rep107.php from true to false, however, as before, this results in an error about no contact defined and does not send an email.

*I see there is now a wiki page on the topic, but nothing actually addresses the multiple recipients other than the link back to my forum post.  I tried installing the mail extension anyway, and tried both the php and smtp options, however both are still only sending to the first contact.


*Also, I have posted a bug in Mantis on this issue, bug number 0003671, but it seems nobody has looked at it yet.  (Sadly/Happily my business is keeping me busy enough that I still have not developed the PHP skills necessary to fix this problem myself). 

So I am posting this so that maybe it comes back into the light as something people need.  The ability to CC some contacts and TO others would also be a really handy asset, though a minor drop in the bucket compares to actually needing to send to multiple recipients in any form.

I do have the work around I figured out way back when (commenting lines 208-215 of sales/includes/db/branches_db.inc and deleting all branch contacts), but now that I am not the only person working in FA in my own company, it would be nice to not have to mess with the code on every update, and not have to go back and delete contacts every time we add a customer.  It works, but it's error prone, and people who come from Microsoft environments (ie practically everyone) don't wrap their head around using workarounds the same as I do, it seems.

Re: emailing multiple contacts


If you change the last parameter in

$contacts = get_branch_contacts($branch['branch_code'], 'invoice', $branch['debtor_no'], true); 

in /reporting/rep107.php to false (default true], all the branch contacts with the action 'invoice' will get the Invoices.

If you don't want to change the core files, you can copy the rep107.php to /company/X/reporting and change the true to false here. The X indicates the table preference number for the client database tables.


Re: emailing multiple contacts


Thanks for the reply, and the clarification.  I took Apmuthu's comments in the original post to mean it should work for general and invoice action types, but when you pointed out the "invoice" type requirement it became obvious.  My bad for not connecting that before.

For testing, I am using 2 branch contacts with different emails that are both configured on my desktop, and one of those contacts is auto-created from the contact that was created when I entered the customer.  As mentioned I am working on a fairly pristine instance; a few things setup under company setup to make the system work, but only one customer and 1 service item in inventory.  To test the sending of mail I have generated a single invoice in the system and am using the reports and analysis page to print/email invoices as required.

I copied rep107 and changed line 138 to false as you suggested, and set the action types to invoice for my 2 branch contacts, and it is now sending me 3 emails; 1 to the first branch contact and 2 to the 2nd branch contact.  I am not clear where it is getting the idea to send 2 emails to the 2nd contact from, but I can see in the local exim logs that it is indeed sending 3 mails instead of 2.  the 0_crm_contacts table is showing one general type of contact for customer, and 2 invoice types of contact for cust_branch.

For grins and giggles, I changed 'invoice' to 'general' on line 138 of rep107.php, on the premise that that will send to all the general type branch contacts, and set the contact types back to general for both branch contacts.  This results in a yellow triangle on the web page, and 4 emails being sent.  Either 3 to the first branch contact and 1 to the second, or one to each branch contact and one to the customer contact and one extra because it is over achieving. 

I deleted both branch contacts, so left with only one customer contact, and this results in one invoice going to the customer contact.  Add a 2nd contact to the customer (not the branch), and I again get the yellow triangle, and 3 emails; one to the first contact and 2 to the 2nd contact.  change rep107 to be 'general' and true, and back to one email to the first contact (expected behaviour).

Change rep107 back to 'general' and false, added 2 contacts back to the branch, so now have 2 branch contacts, 2 customer contacts where one contact is the same between customer and cust_branch, and rep107 is set to general and false.  Now I get 1 email to first customer contact, 2 emails to first branch contact, and 2 emails to second customer contact (using different names on all the contacts so I can see it is sending to both customer and cust_branch), and nothing to the second branch contact.  Exim logs confirm 5 mails leave the system.

So I think still not working as expected.  I can't imagine what, but is it possible I am doing or not doing something that is causing this to not work? 

Very much open to further suggestions.

Re: emailing multiple contacts


I was hashing this over in my sleep last night, thinking I must be doing something wrong.  So this morning I rolled back to my first backup, so basically at the point where I have only my tax number setup.  Tried to setup a customer, but had to get the tax groups setup first, tried to add an item, but had to get item tax types setup first; just illustrating that there isn't much of anything added to the system.

I then added 2 contacts in customer with type general, with unique names, and 2 contacts in branch with type invoice, with unique names.  I then modified rep107 to be invoice and false; then generated a direct invoice; emailed the invoice, and was able to replicate yesterday's situation where I got one invoice to the first branch contact and 2 copies of the invoice to the second branch contact.

So can definitely reproduce the same results.  And still thinking this is not intended behaviour.

Is there any further info I can provide to get this figured?

Re: emailing multiple contacts

I have tried the email routines and I cannot reproduce the double emails on the last contact.
Please make a dump of the customer contacts and the branch contacts. Maybe there are something here.

Or try to elaborate with removing the customer contacts and only use branch contacts.

Try eventually emtying the internet cache.

Anybody here in the forum that can help us?


Re: emailing multiple contacts


Thanks so much for sticking with me on this.

I decided to start from the cleanest slate possible to eliminate any possibility I did a configuration mistake.  so brand new unpacking of the files, empty database: go through the installer, used English Canada CoA, otherwise all defaults except db info.  First thing when logged in is make a tax group, name it GST and select 7% VAT, just to use something very default.  Next add non-exempt item tax type.  Next add item using service category and service item type, everything else default.  Next add customer with customer name, short name, one word in the address field, and my email address, everything else defaults.  Here is my starting platform.

Generate direct invoice and email it: page says one email sent, one email received.

Update Customer contact to have first and last name of Bob Miller, generate invoice: Page says one email sent, one email received.

Clone customer contact, change first name Sally , last name Smith, use alternate email address, generate invoice: Page says one email sent, one email received.

cp reporting/rep107.php company/0/reporting/
vi company/0/reporting/rep107.php
*change line 138 to this:
*$contacts = get_branch_contacts($branch['branch_code'], 'invoice', $branch['debtor_no'], false);

Modify Branch contact to have first name Fred, last name Jones, contact active for invoice generate invoice: pages says one email sent, Fred Jones received an email.

Clone branch contact, change first name Joe, last name Public, use alternate email address.  generate invoice: page says two emails sent, Fred and Joe received emails.  Woot!! first time I have seen this work.  So something else about my install is causing the problem.

Install (my preferred) Response theme and switch to it in preferences, generate invoice: page says two emails sent, Fred and Joe receive emails. 

So it seems that it does work as advertised, but something I did made it not work that way.  Fortunately I took fairly careful notes about all the things I did to do my setup, so I will step through them again one by one and see if I can nail down exactly where in the process it breaks and I will report back.

Thanks again for your help!

Re: emailing multiple contacts


So by good fortune the problem was at the beginning of the config process and not at the end smile

Problem setting is the BCC field under company setup=>company setup.  When it is set, an email to the 2nd branch contact is generated twice.

Re: emailing multiple contacts


just a little bit more follow up.

I restored my original company that I had been working on and using to report this issue, removed the BCC field, and set rep107 to 'invoice' and false and branch contacts to invoice and mail delivery works as expected.

To see what would happen, I set rep107 to 'general' and false, and this caused it to email the customer contact, which was still set to general.  I guess this is expected behaviour in that if it couldn't find a correct contact type in branch contact, it fails over the customer contact, so good up to here.

From here, I change the action type on the two branch contacts to general, and I get the same behaviour as the BCC field being set; a duplicate email is sent to the 2nd branch contact.  My expectation is that it would behave the same for general contacts as it would for invoice contacts, ie send one email to each general contact type in the branch contacts.

Maybe these two anomalies causing duplicate mails are related, or a clue that point to the same root cause?

As per the wiki, invoice type will do invoices, receipts and statements, but not quotations.  I don't do a lot of quotes, but it's not like I never use the feature, so my prediction is that if branch contacts are set to invoice, it will fail over to customer contact of general type; testing proves this to be true, the quote is emailed to the general type of customer contact.  And set customer contact to invoice, and error says no contact of the correct type to email to.  So all of that behaving as expected, can't be sending quotes if all the contact types are set to invoice.

My concern here is that if I need to keep the same list of contacts in both branch and customer and make sure one is set to invoice and one is set to general, or eliminate one set of contacts altogether, then I am back in the same position I am trying to fix, which is to make contact management less error prone and more intuitive for other users.  It would seem that being able to use general type for multiple contacts in the branch would be the solution; that way contacts just go in with more or less default settings and the end users don't have to remember to do special things every time they add a customer or contact.