SuiteCrm 电子邮件通知重复
SuiteCrm Email Notifications Duplicating
我在 suitecrm 中创建了一个模块,允许用户创建或查看 nc 案例。创建 nc 案例时,会向分配给此变量 $rev_email 的人发送电子邮件通知,但是当发送电子邮件时,它会在该人的收件箱中重复,而管理员应该只收到一次。
function createCaseEmail(&$email,$rev_email,$subject,$bean,$xtpl){
/* Set Email Subject */
$email->Subject=$subject;
/* Get NC Case Number */
$case_number = $bean ->case_number;
$xtpl->assign('Case_Number', $case_number );
/* Get NC Subject */
$xtpl->assign('Case_Subject', $bean->name);
/* Get Case Description */
$xtpl->assign('Case_Desc', $bean->description_c);
/* Create email message using email template and data above */
$xtpl->parse('main');
$email->Body = from_html($xtpl->text('main'));
return $email;
}
class cases_email_notification
{
function send_notification($bean, $event, $arguments)
{
/*Get sugar email engine*/
$email = new SugarPHPMailer();
$email->From = 'it@gmail.com';
$email->FromName ='SuiteCRM';
$rev_email = 'admin@gmail.com';
/* Get sugar template engine */
$xtpl = new XTemplate("XTemplate/CasesEmailTemplate.html");
/*GEt the URL for the NC Case */
$url = $GLOBALS['sugar_config']['site_url'].'index.php?module=Cases&action=DetailView&record='.$bean->id;
$xtpl -> assign('URL', $url);
/* Get Case ID */
$id = $bean->getFieldValue('id');
if(empty($bean->fetched_row['id'])){
$email=createCaseEmail($email,$rev_email,'New Case Email Notification',$bean,$xtpl);
/* Send email to Production Department */
$email->addAddress($rev_email);
}
//Send email
$email->isHTML(true);
$email->prepForOutbound();
$email->setMailerForSystem();
if(!$email->Send()){
$GLOBALS['log']->info("Could not send notification email: ". $email->ErrorInfo);
}
}
}
before_save 挂钩中的复制问题很常见。我们希望逻辑钩子第一次到 运行。为了确保这一点,我们可以使用一个名为 $already_ran
的静态变量。
class cases_email_notification
{
static $already_ran = false;
function send_notification($bean, $event, $arguments)
{
$GLOBALS['log']->info("send_notification start!"
if(self::$already_ran == true) return;
self::$already_ran = true;
/*Get sugar email engine*/
$email = new SugarPHPMailer();
$email->setMailerForSystem();
$email->From = 'it@gmail.com';
$email->FromName ='SuiteCRM';
/* Set Email Subject */
$email->Subject=$subject;
$email->Body = '';
$email->prepForOutbound();
/* Send email to Production Department */
$email->addAddress('admin@gmail.com');
if(!$email->Send()){
$GLOBALS['log']->info("Could not send notification email: ". $email->ErrorInfo);
} else {
$GLOBALS['log']->info("I send notification email!!!"
}
}
}
我在 suitecrm 中创建了一个模块,允许用户创建或查看 nc 案例。创建 nc 案例时,会向分配给此变量 $rev_email 的人发送电子邮件通知,但是当发送电子邮件时,它会在该人的收件箱中重复,而管理员应该只收到一次。
function createCaseEmail(&$email,$rev_email,$subject,$bean,$xtpl){
/* Set Email Subject */
$email->Subject=$subject;
/* Get NC Case Number */
$case_number = $bean ->case_number;
$xtpl->assign('Case_Number', $case_number );
/* Get NC Subject */
$xtpl->assign('Case_Subject', $bean->name);
/* Get Case Description */
$xtpl->assign('Case_Desc', $bean->description_c);
/* Create email message using email template and data above */
$xtpl->parse('main');
$email->Body = from_html($xtpl->text('main'));
return $email;
}
class cases_email_notification
{
function send_notification($bean, $event, $arguments)
{
/*Get sugar email engine*/
$email = new SugarPHPMailer();
$email->From = 'it@gmail.com';
$email->FromName ='SuiteCRM';
$rev_email = 'admin@gmail.com';
/* Get sugar template engine */
$xtpl = new XTemplate("XTemplate/CasesEmailTemplate.html");
/*GEt the URL for the NC Case */
$url = $GLOBALS['sugar_config']['site_url'].'index.php?module=Cases&action=DetailView&record='.$bean->id;
$xtpl -> assign('URL', $url);
/* Get Case ID */
$id = $bean->getFieldValue('id');
if(empty($bean->fetched_row['id'])){
$email=createCaseEmail($email,$rev_email,'New Case Email Notification',$bean,$xtpl);
/* Send email to Production Department */
$email->addAddress($rev_email);
}
//Send email
$email->isHTML(true);
$email->prepForOutbound();
$email->setMailerForSystem();
if(!$email->Send()){
$GLOBALS['log']->info("Could not send notification email: ". $email->ErrorInfo);
}
}
}
before_save 挂钩中的复制问题很常见。我们希望逻辑钩子第一次到 运行。为了确保这一点,我们可以使用一个名为 $already_ran
的静态变量。
class cases_email_notification
{
static $already_ran = false;
function send_notification($bean, $event, $arguments)
{
$GLOBALS['log']->info("send_notification start!"
if(self::$already_ran == true) return;
self::$already_ran = true;
/*Get sugar email engine*/
$email = new SugarPHPMailer();
$email->setMailerForSystem();
$email->From = 'it@gmail.com';
$email->FromName ='SuiteCRM';
/* Set Email Subject */
$email->Subject=$subject;
$email->Body = '';
$email->prepForOutbound();
/* Send email to Production Department */
$email->addAddress('admin@gmail.com');
if(!$email->Send()){
$GLOBALS['log']->info("Could not send notification email: ". $email->ErrorInfo);
} else {
$GLOBALS['log']->info("I send notification email!!!"
}
}
}