Skip to content

Commit

Permalink
Use Email.send api instead of MEssageTemplate.send so it records an a…
Browse files Browse the repository at this point in the history
…ctivity
  • Loading branch information
Rich Lott / Artful Robot committed Mar 3, 2022
1 parent 0ef9d3d commit e7f999c
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions Civi/Inlay/Petition.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ public static function getSignerOptInFieldID() {
*/
public function processRequest(ApiRequest $request) {

Civi::log()->debug('Petition inlay request: ' . json_encode($request->getBody()));
$data = $this->cleanupInput($request->getBody());

if (empty($data['token'])) {
Expand Down Expand Up @@ -438,24 +439,36 @@ public function sendThankYouEmail($contactID, $data) {

$from = civicrm_api3('OptionValue', 'getvalue', [ 'return' => "label", 'option_group_id' => "from_email_address", 'is_default' => 1]);

// We use the email send in the data, as that's what they'd expect.
$params = [
'id' => $this->config['thanksMsgTplID'],
'from' => $from,
'to_email' => $data['email'],
// 'bcc' => "[email protected]",
'contact_id' => $contactID,
'disable_smarty' => 1,
/*
'template_params' =>
[ 'foo' => 'hello',
// {$foo} in templates 'bar' => '123',
// {$bar} in templates ],
*/
];

try {
civicrm_api3('MessageTemplate', 'send', $params);
// This was the original, using MessageTemplate.send API
//
// // We use the email send in the data, as that's what they'd expect.
// $params = [
// 'id' => $this->config['thanksMsgTplID'],
// 'from' => $from,
// 'to_email' => $data['email'],
// // 'bcc' => "[email protected]",
// 'contact_id' => $contactID,
// 'disable_smarty' => 1,
// /*
// 'template_params' =>
// [ 'foo' => 'hello',
// // {$foo} in templates 'bar' => '123',
// // {$bar} in templates ],
// ];
// civicrm_api3('MessageTemplate', 'send', $params);
// */

// This is the new one using Email.send from the EmailAPI extension, which also saves it as an activity.
$params = [
'template_id' => $this->config['thanksMsgTplID'],
'alternative_receiver_address' => $data['email'],
// 'bcc' => "[email protected]",
'contact_id' => $contactID,
'disable_smarty' => 1,
'activity_details' => 'tplName',
];
civicrm_api3('Email', 'send', $params);
}
catch (\Exception $e) {
// Log silently.
Expand Down

0 comments on commit e7f999c

Please sign in to comment.