6

We have a custom module that we use to do event registrations (non - paid), however i was wondering is there anyway through the API of being able to trigger CiviCRM sending a confirmation registration email when we submit the registration via API?

3 Answers 3

4

There is a send email API in an extension that should be able to handle that? Not the automatic sending but you can trigger the API in whatever processing you do. Extension can be found here: https://github.com/CiviCooP/org.civicoop.emailapi

2
  • This extension is available in the CiviCRM Extensions Directory online, and it looks like it's new in 2015 and actively supported. (Thanks Jaap Jansma and CiviCooP!) Is this correct that it's only confirmed compatible through Civi 4.5, and so it would not appear in a Civi 4.6.7 list of "native" extensions on the civicrm/admin/extensions page? Aug 21, 2015 at 14:15
  • Yes, that is correct (and it is also updated by Ixiam if we are thanking :-) Aug 24, 2015 at 6:53
3

I haven't tried the org.civicoop.emailapi extension, but I did give it a quick skim, and it didn't look like it would be suitable for the use case of an event registration confirmation email. I didn't see where it would accept params for the event ID or the participant ID, so while it might be able to send the appropriate template, much of the data wouldn't be populated.

Instead I ended up using a core BAO. This is not recommended, because presumably the method is not intended to be a public interface and could change from one version to the next.

Nevertheless, it was expedient. Here's some sample code for anyone else who may need to do this:

<?php

// your contact ID may come from elsewhere
$cid = $form->getVar('_primary_volunteer_id');

foreach ($form->_submitValues['field_added_by_buildform_hook'] as $eventId) {
  $participant = civicrm_api3('Participant', 'create', array(
    'contact_id' => $cid,
    'event_id' => $eventId,
    'role_id' => 'Attendee',
    'source' => 'My Customized Form',
  ));

  // elsewhere I have called civicrm_api3('Event', 'get', $params)
  // to populate $eventData
  $locBlock = civicrm_api3('LocBlock', 'getsingle', array(
    'id' => $eventData[$eventId]['loc_block_id'],
    'return' => 'all',
  ));
  // for some reason, the BAO expects 1-indexing rather than 0-indexing
  $locBlock['address'] = array(1 => $locBlock['address']);

  // Note: other stuff data can go into $mailParams, such
  // as fee information. It's not well-documented, and it
  // wasn't relevant to my use case, so I didn't bother.
  $mailParams = array(
    'event' => $eventData[$eventId],
    'location' => $locBlock,
  );
  CRM_Event_BAO_Event::sendMail($cid, $mailParams, $participant['id']);
}
1
  • this is really handy - thanks - I was thinking that you could potentially add an option to the participant.create API send_confirmation to take care of sending the confirmation email. Feb 19, 2019 at 12:13
1

There is a new extension called Event Messages that an alternative way to send confirmation emails for CiviCRM Events.

It creates an additional tab within CiviCRM Events that allows you to define different message templates to be sent based on conditions (including the participants status, role and preferred language). It will also allow you to suppress CiviCRM's regular emails.

Probably that should cover the use case described here.

1

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.