forked from artfulrobot/inlaypetition
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Email.send api instead of MEssageTemplate.send so it records an a…
…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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'])) { | ||
|
@@ -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. | ||
|