要在Civicrm中添加捐款支付时自动发送感谢邮件,您可以按照以下步骤操作:
-
首先,您需要在Civicrm中创建一个感谢邮件模板。转到Civicrm后台管理,选择“通信”>“邮件模板”>“新增邮件模板”。您可以添加您自己的感谢内容,并使用相关的变量来个性化邮件。
-
创建一个新的Civicrm扩展,用于添加自定义代码。在您的Civicrm扩展目录中创建一个新的文件夹,例如“MyExtension”。在该文件夹中创建一个名为“MyExtension.php”的文件,并添加以下代码:
<?php
use CRM_Core_PseudoConstant;
use CRM_Contribute_DAO_Contribution;
use CRM_Core_BAO_MessageTemplates;
/**
* Implements hook_civicrm_postProcess().
*/
function myextension_civicrm_postProcess($formName, &$form) {
// Check if the form is for adding a contribution payment.
if ($formName == 'CRM_Contribute_Form_Contribution_Confirm') {
// Get the contribution ID.
$contributionId = $form->getVar('_id');
// Load the contribution data.
$contribution = new CRM_Contribute_DAO_Contribution();
$contribution->id = $contributionId;
$contribution->find(true);
// Get the contact ID of the contributor.
$contactId = $contribution->contact_id;
// Get the email address of the contact.
$email = CRM_Core_BAO_MessageTemplates::getContactEmail($contactId);
// Get the email template ID for the thank you email.
$templateId = CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_MessageTemplates', 'msg_title', 'Thank You Letter');
// Send the thank you email.
CRM_Core_BAO_MessageTemplates::sendTemplate($templateId, $email, $contactId, array(), $contributionId);
}
}
- 在Civicrm扩展目录中创建一个名为“myextension.info.xml”的文件,并添加以下代码:
<?xml version="1.0" encoding="UTF-8" ?>
<extension key="myextension" type="module">
<name>My Extension</name>
<version>1.0</version>
<description>Adds custom functionality to automatically send thank you emails when a donation payment is added.</description>
<file>MyExtension.php</file>
</extension>
-
将“MyExtension”文件夹复制到Civicrm的扩展目录中。
-
登录到Civicrm后台管理,转到“系统设置”>“扩展”。您应该能够看到您刚刚创建的扩展。单击“安装”按钮来安装扩展。
现在,当您在Civicrm中添加捐款付款时,将自动发送感谢邮件给捐款人。您可以根据需要修改感谢邮件模板和自定义代码。