function save($check_notify = false) { global $current_user, $sugar_config; parent::save($check_notify); $email_template = new EmailTemplate(); if ($_REQUEST['module'] == 'Import') { //Don't send email on import return; } $signature = array(); $addDelimiter = true; $aop_config = $sugar_config['aop']; if (!empty($this->contact_id)) { $emails = $this->getEmailForUser(); if ($aop_config['user_email_template_id']) { $email_template->retrieve($aop_config['user_email_template_id']); } $addDelimiter = false; } elseif ($this->assigned_user_id && !$this->internal) { $emails = $this->getEmailForContact(); if ($aop_config['contact_email_template_id']) { $email_template->retrieve($aop_config['contact_email_template_id']); $signature = $current_user->getDefaultSignature(); } } if ($emails && $email_template) { $GLOBALS['log']->info("AOPCaseUpdates: Calling send email"); $res = $this->sendEmail($emails, $email_template, $signature, $this->case_id, $addDelimiter); } }
function canSendPassword() { require_once 'include/SugarPHPMailer.php'; global $mod_strings; global $current_user; global $app_strings; $mail = new SugarPHPMailer(); $emailTemp = new EmailTemplate(); $mail->setMailerForSystem(); $emailTemp->disable_row_level_security = true; if ($current_user->is_admin) { if ($emailTemp->retrieve($GLOBALS['sugar_config']['passwordsetting']['generatepasswordtmpl']) == '') { return $mod_strings['LBL_EMAIL_TEMPLATE_MISSING']; } if (empty($emailTemp->body) && empty($emailTemp->body_html)) { return $app_strings['LBL_EMAIL_TEMPLATE_EDIT_PLAIN_TEXT']; } if ($mail->Mailer == 'smtp' && $mail->Host == '') { return $mod_strings['ERR_SERVER_SMTP_EMPTY']; } $email_errors = $mod_strings['ERR_EMAIL_NOT_SENT_ADMIN']; if ($mail->Mailer == 'smtp') { $email_errors .= "<br>-" . $mod_strings['ERR_SMTP_URL_SMTP_PORT']; } if ($mail->SMTPAuth) { $email_errors .= "<br>-" . $mod_strings['ERR_SMTP_USERNAME_SMTP_PASSWORD']; } $email_errors .= "<br>-" . $mod_strings['ERR_RECIPIENT_EMAIL']; $email_errors .= "<br>-" . $mod_strings['ERR_SERVER_STATUS']; return $email_errors; } else { return $mod_strings['LBL_EMAIL_NOT_SENT']; } }
function canSendPassword() { global $mod_strings, $current_user, $app_strings; require_once "modules/OutboundEmailConfiguration/OutboundEmailConfigurationPeer.php"; if ($current_user->is_admin) { $emailTemplate = new EmailTemplate(); $emailTemplate->disable_row_level_security = true; if ($emailTemplate->retrieve($GLOBALS['sugar_config']['passwordsetting']['generatepasswordtmpl']) == '') { return $mod_strings['LBL_EMAIL_TEMPLATE_MISSING']; } if (empty($emailTemplate->body) && empty($emailTemplate->body_html)) { return $app_strings['LBL_EMAIL_TEMPLATE_EDIT_PLAIN_TEXT']; } if (!OutboundEmailConfigurationPeer::validSystemMailConfigurationExists($current_user)) { return $mod_strings['ERR_SERVER_SMTP_EMPTY']; } $emailErrors = $mod_strings['ERR_EMAIL_NOT_SENT_ADMIN']; try { $config = OutboundEmailConfigurationPeer::getSystemDefaultMailConfiguration(); if ($config instanceof OutboundSmtpEmailConfiguration) { $emailErrors .= "<br>-{$mod_strings['ERR_SMTP_URL_SMTP_PORT']}"; if ($config->isAuthenticationRequired()) { $emailErrors .= "<br>-{$mod_strings['ERR_SMTP_USERNAME_SMTP_PASSWORD']}"; } } } catch (MailerException $me) { // might want to report the error } $emailErrors .= "<br>-{$mod_strings['ERR_RECIPIENT_EMAIL']}"; $emailErrors .= "<br>-{$mod_strings['ERR_SERVER_STATUS']}"; return $emailErrors; } return $mod_strings['LBL_EMAIL_NOT_SENT']; }
public function testAssignedUserName() { global $locale; require_once 'include/Localization/Localization.php'; $locale = new Localization(); $testName = $locale->getLocaleFormattedName($this->user->first_name, $this->user->last_name); $testTemplate = new EmailTemplate(); $testTemplate->retrieve($this->emailTemplate->id); $this->assertEquals($testName, $testTemplate->assigned_user_name, 'Assert that the assigned_user_name is the locale formatted name value'); }
function updateUser($bean, $event, $arguments) { if (isset($bean->joomla_account_access) && $bean->joomla_account_access != '') { global $sugar_config; $aop_config = $sugar_config['aop']; $template = new EmailTemplate(); $template->retrieve($aop_config['joomla_account_creation_email_template_id']); $object_arr['Contacts'] = $bean->id; $body_html = aop_parse_template($template->body_html, $object_arr); $body_html = str_replace("\$joomla_pass", $bean->joomla_account_access, $body_html); $body_html = str_replace("\$portal_address", $aop_config['joomla_url'], $body_html); $body_plain = aop_parse_template($template->body, $object_arr); $body_plain = str_replace("\$joomla_pass", $bean->joomla_account_access, $body_plain); $body_plain = str_replace("\$portal_address", $aop_config['joomla_url'], $body_plain); $this->sendEmail($bean->email1, $template->subject, $body_html, $body_plain, $bean); } }
function getTemplateValidationMessages($templateId) { $msgs = array(); if (!$templateId) { $msgs[] = 'LBL_NO_SELECTED_TEMPLATE'; } else { $template = new EmailTemplate(); $template->retrieve($templateId); if (!$template->subject) { $msgs[] = 'LBL_NO_SUBJECT'; } if (!$template->body_html) { $msgs[] = 'LBL_NO_HTML_BODY_CONTENTS'; } if (!$template->body) { $msgs[] = 'LBL_NO_BODY_CONTENTS'; } } return $msgs; }
if (!$emailman->verify_campaign($row['marketing_id'])) { $GLOBALS['log']->fatal('Error verifying templates for the campaign, exiting'); continue; } //verify the email template too.. //find the template associated with marketing message. make sure that template has a subject and //a non-empty body if (!isset($template_status[$row['marketing_id']])) { if (!class_exists('EmailMarketing')) { } $current_emailmarketing = new EmailMarketing(); $current_emailmarketing->retrieve($row['marketing_id']); if (!class_exists('EmailTemplate')) { } $current_emailtemplate = new EmailTemplate(); $current_emailtemplate->retrieve($current_emailmarketing->template_id); } //acquire a lock. //if the database does not support repeatable read isolation by default, we might get data that does not meet //the criteria in the original query, and we care most about the in_queue_date and process_date_time, //if they are null or in past(older than 24 horus) then we are okay. $lock_query = "UPDATE emailman SET in_queue=1, in_queue_date=" . $db->now() . " WHERE id = " . intval($row['id']); $lock_query .= " AND (in_queue ='0' OR in_queue IS NULL OR ( in_queue ='1' AND in_queue_date <= " . $db->convert($db->quoted($timedate->fromString("-1 day")->asDb()), "datetime") . "))"; //if the query fails to execute.. terminate campaign email process. $lock_result = $db->query($lock_query, true, 'Error acquiring a lock for emailman entry.'); $lock_count = $db->getAffectedRowCount($lock_result); //do not process the message if unable to acquire lock. if ($lock_count != 1) { $GLOBALS['log']->fatal("Error acquiring lock for the emailman entry, skipping email delivery. lock status={$lock_count} " . print_r($row, true)); continue; //do not process this row we will examine it after 24 hrs. the email address based dupe check is in place too.
* All Rights Reserved. * Contributor(s): ______________________________________.. ********************************************************************************/ require_once 'modules/Campaigns/utils.php'; //if campaign_id is passed then we assume this is being invoked from the campaign module and in a popup. $has_campaign = true; $inboundEmail = true; if (!isset($_REQUEST['campaign_id']) || empty($_REQUEST['campaign_id'])) { $has_campaign = false; } if (!isset($_REQUEST['inboundEmail']) || empty($_REQUEST['inboundEmail'])) { $inboundEmail = false; } $focus = new EmailTemplate(); if (isset($_REQUEST['record'])) { $focus->retrieve($_REQUEST['record']); } $old_id = ''; if (isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') { $old_id = $focus->id; // for attachments down below $focus->id = ""; } //setting default flag value so due date and time not required if (!isset($focus->id)) { $focus->date_due_flag = 1; } //needed when creating a new case with default values passed in if (isset($_REQUEST['contact_name']) && is_null($focus->contact_name)) { $focus->contact_name = $_REQUEST['contact_name']; }
} else { $leaveMessagesOnMailServer = $app_strings['LBL_EMAIL_NO']; } // else if (!isset($storedOptions['leaveMessagesOnMailServer']) || $storedOptions['leaveMessagesOnMailServer'] == 1) { $leaveMessagesOnMailServer = $app_strings['LBL_EMAIL_YES']; } else { $leaveMessagesOnMailServer = $app_strings['LBL_EMAIL_NO']; } // else $distrib_method = isset($storedOptions['distrib_method']) ? $storedOptions['distrib_method'] : ""; $create_case_email_template = isset($storedOptions['create_case_email_template']) ? $storedOptions['create_case_email_template'] : ""; } if (!empty($create_case_email_template)) { $et = new EmailTemplate(); $et->retrieve($create_case_email_template); $create_case_email_template_name = $et->name; } if (!empty($distrib_method)) { $distributionMethod = $app_list_strings['dom_email_distribution_for_auto_create'][$distrib_method]; } // if $xtpl = new XTemplate('modules/InboundEmail/DetailView.html'); //// ERRORS from Save if (isset($_REQUEST['error'])) { $xtpl->assign('ERROR', "<div class='error'>" . $mod_strings['ERR_NO_OPTS_SAVED'] . "</div>"); } //cma, June 24,2008 - Fix bug 21670. User status and group/personal statements are not localized. $userStatus = $mod_strings['LBL_STATUS_ACTIVE']; if ('Inactive' == $focus->status) { $userStatus = $mod_strings['LBL_STATUS_INACTIVE'];
function verify_campaign($marketing_id) { if (!isset($this->verified_email_marketing_ids[$marketing_id])) { if (!class_exists('EmailMarketing')) { } $email_marketing = new EmailMarketing(); $ret = $email_marketing->retrieve($marketing_id); if (empty($ret)) { $GLOBALS['log']->fatal('Error retrieving marketing message for the email campaign. marketing_id = ' . $marketing_id); return false; } //verify the email template. if (empty($email_marketing->template_id)) { $GLOBALS['log']->fatal('Error retrieving template for the email campaign. marketing_id = ' . $marketing_id); return false; } if (!class_exists('EmailTemplate')) { } $emailtemplate = new EmailTemplate(); $ret = $emailtemplate->retrieve($email_marketing->template_id); if (empty($ret)) { $GLOBALS['log']->fatal('Error retrieving template for the email campaign. template_id = ' . $email_marketing->template_id); return false; } if (empty($emailtemplate->subject) and empty($emailtemplate->body) and empty($emailtemplate->body_html)) { $GLOBALS['log']->fatal('Email template is empty. email_template_id=' . $email_marketing->template_id); return false; } } $this->verified_email_marketing_ids[$marketing_id] = 1; return true; }
$sms_field = $e->get_custom_phone_field(); $msg = ""; $pid = $_GET['pid']; $pids = explode(",", $pid); $ptype = $_GET['ptype']; $pname = isset($_GET['pname']) ? $_GET['pname'] : ""; $phone_number = $_GET['num']; $onclick = "send_sms();"; $send_to_multi = $_GET['num'] == 'multi' ? '1' : '0'; } include_once "modules/Administration/sugartalk_smsPhone/sms_editor.php"; break; case "template": if (isset($_GET['id'])) { $et = new EmailTemplate(); $et->retrieve($_GET['id']); echo $et->body; } break; default: echo ""; } } else { // just draw the gateway settings panel $_POST['account_id'] = '123'; if (isset($_POST['account_id'])) { $flag = isset($_POST['use_template']) ? true : false; $sms->params['sms_instance_id'] = trim($_POST['account_id']); $sms->params['uses_sms_template'] = $flag; $sms->params['sugartalk_url'] = trim($_POST['sugartalk_url']); $sms->params['sender'] = trim($_POST['sender']);
function run_action(SugarBean $bean, $params = array(), $in_save = false) { global $sugar_config, $beanList; include_once 'modules/EmailTemplates/EmailTemplate.php'; require_once 'modules/AOW_Actions/actions/templateParser.php'; $emailTemp = new EmailTemplate(); $emailTemp->retrieve($params['email_template']); if ($emailTemp->id == '') { return false; } $object_arr[$bean->module_dir] = $bean->id; foreach ($bean->field_defs as $bean_arr) { if ($bean_arr['type'] == 'relate') { if (isset($bean_arr['module']) && $bean_arr['module'] != '' && isset($bean_arr['id_name']) && $bean_arr['id_name'] != '' && $bean_arr['module'] != 'EmailAddress') { $relate_bean = new $beanList[$bean_arr['module']](); if (!isset($object_arr[$relate_bean->module_dir])) { $object_arr[$relate_bean->module_dir] = $bean->{$bean_arr}['id_name']; } } } else { if ($bean_arr['type'] == 'link') { if (!isset($bean_arr['module']) || $bean_arr['module'] == '') { $bean_arr['module'] = getRelatedModule($bean->module_dir, $bean_arr['name']); } if (isset($bean_arr['module']) && $bean_arr['module'] != '' && !isset($object_arr[$bean_arr['module']]) && $bean_arr['module'] != 'EmailAddress') { $linkedBeans = $bean->get_linked_beans($bean_arr['name'], $bean_arr['module']); if ($linkedBeans) { $linkedBean = $linkedBeans[0]; if (!isset($object_arr[$linkedBean->module_dir])) { $object_arr[$linkedBean->module_dir] = $linkedBean->id; } } } } } } $object_arr['Users'] = $bean->assigned_user_id; $parsedSiteUrl = parse_url($sugar_config['site_url']); $host = $parsedSiteUrl['host']; if (!isset($parsedSiteUrl['port'])) { $parsedSiteUrl['port'] = 80; } $port = $parsedSiteUrl['port'] != 80 ? ":" . $parsedSiteUrl['port'] : ''; $path = !empty($parsedSiteUrl['path']) ? $parsedSiteUrl['path'] : ""; $cleanUrl = "{$parsedSiteUrl['scheme']}://{$host}{$port}{$path}"; $url = $cleanUrl . "/index.php?module={$bean->module_dir}&action=DetailView&record={$bean->id}"; $subject = str_replace("\$contact_user", "\$user", $emailTemp->subject); $body_html = str_replace("\$contact_user", "\$user", $emailTemp->body_html); $body_plain = str_replace("\$contact_user", "\$user", $emailTemp->body); $subject = aowTemplateParser::parse_template($subject, $object_arr); $body_html = aowTemplateParser::parse_template($body_html, $object_arr); $body_html = str_replace("\$url", $url, $body_html); $body_plain = aowTemplateParser::parse_template($body_plain, $object_arr); $body_plain = str_replace("\$url", $url, $body_plain); $emails = $this->getEmailsFromParams($bean, $params); return $this->sendEmail($emails['to'], $subject, $body_html, $body_plain, $bean, $emails['cc'], $emails['bcc']); }
/** * handles auto-responses to inbound emails * * @param object email Email passed as reference */ function handleAutoresponse(&$email, &$contactAddr) { if ($this->template_id) { $GLOBALS['log']->debug('found auto-reply template id - prefilling and mailing response'); if ($this->getAutoreplyStatus($contactAddr) && $this->checkOutOfOffice($email->name) && $this->checkFilterDomain($email)) { // if we haven't sent this guy 10 replies in 24hours if (!empty($this->stored_options)) { $storedOptions = unserialize(base64_decode($this->stored_options)); } // get FROM NAME if (!empty($storedOptions['from_name'])) { $from_name = $storedOptions['from_name']; $GLOBALS['log']->debug('got from_name from storedOptions: ' . $from_name); } else { // use system default $rName = $this->db->query('SELECT value FROM config WHERE name = \'fromname\''); if (is_resource($rName)) { $aName = $this->db->fetchByAssoc($rName); } if (!empty($aName['value'])) { $from_name = $aName['value']; } else { $from_name = ''; } } // get FROM ADDRESS if (!empty($storedOptions['from_addr'])) { $from_addr = $storedOptions['from_addr']; } else { $rAddr = $this->db->query('SELECT value FROM config WHERE name = \'fromaddress\''); if (is_resource($rAddr)) { $aAddr = $this->db->fetchByAssoc($rAddr); } if (!empty($aAddr['value'])) { $from_addr = $aAddr['value']; } else { $from_addr = ''; } } // handle to: address, prefer reply-to if (!empty($email->reply_to_email)) { $to[0]['email'] = $email->reply_to_email; } else { $to[0]['email'] = $email->from_addr; } // handle to name: address, prefer reply-to if (!empty($email->reply_to_name)) { $to[0]['display'] = $email->reply_to_name; } elseif (!empty($email->from_name)) { $to[0]['display'] = $email->from_name; } if (!class_exists('EmailTemplate')) { require_once 'modules/EmailTemplates/EmailTemplate.php'; } $et = new EmailTemplate(); $et->retrieve($this->template_id); if (empty($et->subject)) { $et->subject = ''; } if (empty($et->body)) { $et->body = ''; } if (empty($et->body_html)) { $et->body_html = ''; } $reply = new Email(); $reply->type = 'out'; $reply->to_addrs = $to[0]['email']; $reply->to_addrs_arr = $to; $reply->cc_addrs_arr = array(); $reply->bcc_addrs_arr = array(); $reply->from_name = $from_name; $reply->from_addr = $from_addr; $reply->name = $et->subject; $reply->description = $et->body; $reply->description_html = $et->body_html; $GLOBALS['log']->debug('saving and sending auto-reply email'); //$reply->save(); // don't save the actual email. $reply->send(); $this->setAutoreplyStatus($contactAddr); } else { $GLOBALS['log']->debug('InboundEmail: auto-reply threshold reached for email (' . $contactAddr . ') - not sending auto-reply'); } } }
function run_action(SugarBean $bean, $params = array()) { global $sugar_config; include_once 'modules/EmailTemplates/EmailTemplate.php'; $emailTemp = new EmailTemplate(); $emailTemp->retrieve($params['email_template']); $object_arr[$bean->module_dir] = $bean->id; $parsedSiteUrl = parse_url($sugar_config['site_url']); $host = $parsedSiteUrl['host']; if (!isset($parsedSiteUrl['port'])) { $parsedSiteUrl['port'] = 80; } $port = $parsedSiteUrl['port'] != 80 ? ":" . $parsedSiteUrl['port'] : ''; $path = !empty($parsedSiteUrl['path']) ? $parsedSiteUrl['path'] : ""; $cleanUrl = "{$parsedSiteUrl['scheme']}://{$host}{$port}{$path}"; $url = $cleanUrl . "/index.php?module={$bean->module_dir}&action=DetailView&record={$bean->id}"; $subject = $emailTemp->parse_template($emailTemp->subject, $object_arr); $body_html = $emailTemp->parse_template($emailTemp->body_html, $object_arr); $body_html = str_replace("\$url", $url, $body_html); $body_plain = $emailTemp->parse_template($emailTemp->body, $object_arr); $body_plain = str_replace("\$url", $url, $body_plain); $email = $this->getEmailFromParams($bean, $params); return $this->sendEmail($email, $subject, $body_html, $body_plain, $bean); }
/** * Send Email with attachment Report to specified emails * @param string $attachFileName * name of report file * @param string $attachFilePath * path to report file for read it and attach to email * @param array $toAddresses * array with email and names of contacts for send him this email * array( array('email' => EMAIL_ADDR, 'display' => DISPLAY_NAME) ) * @param string $templateId * optional argument. Id of Email template * @param SugarBean $bean * optional argument, uses for parse template with values of this bean * @return array * return array with status send email in this format: array('status' => TRUE_OR_FALSE, 'error' => ERROR_MSG) */ public static function sendEmailTemplate($attachFileName, $attachFilePath, $toAddresses, $templateId = '', $bean = NULL) { global $locale, $current_user, $app_strings; $sea = new SugarEmailAddress(); $answer = array('status' => true, 'error' => ''); $email = new Email(); $email->email2init(); $email->type = 'out'; $email->status = 'sent'; $email->id = create_guid(); $email->new_with_id = true; $emailTemplate = new EmailTemplate(); $emailTemplate->retrieve($templateId); if (empty($emailTemplate->subject)) { $emailTemplate->subject = $attachFileName; //set file name as subject } $email->name = $emailTemplate->subject; $email->description = $emailTemplate->body; $email->description_html = '<html><body>' . $emailTemplate->body_html . '</body></html>'; $mail = new SugarPHPMailer(); $mail = $email->setMailer($mail, '', ''); if (empty($mail->Host)) { if ($mail->oe->type == 'system') { $answer['error'] = $app_strings['LBL_EMAIL_ERROR_PREPEND'] . $app_strings['LBL_EMAIL_INVALID_SYSTEM_OUTBOUND']; } else { $answer['error'] = $app_strings['LBL_EMAIL_ERROR_PREPEND'] . $app_strings['LBL_EMAIL_INVALID_PERSONAL_OUTBOUND']; } $answer['status'] = false; return $answer; } $object_arr = array(); if ($bean !== NULL) { $object_arr[$bean->module_dir] = $bean->id; } foreach ($toAddresses as $addrMeta) { $addr = $addrMeta['email']; $beans = $sea->getBeansByEmailAddress($addr); foreach ($beans as $bean) { if (!isset($object_arr[$bean->module_dir])) { $object_arr[$bean->module_dir] = $bean->id; } } } $object_arr['Users'] = $current_user->id; $email->description_html = $email->decodeDuringSend(from_html(EmailTemplate::parse_template($email->description_html, $object_arr))); $email->description = $email->decodeDuringSend(html_entity_decode(EmailTemplate::parse_template($email->description, $object_arr), ENT_COMPAT, 'UTF-8')); $email->name = from_html(EmailTemplate::parse_template($email->name, $object_arr)); $mail->Body = $email->description_html; $mail->AltBody = $email->description; $mail->Subject = $email->name; $replyToAddress = $current_user->emailAddress->getReplyToAddress($current_user); $defaults = $current_user->getPreferredEmail(); $mail->From = $defaults['email']; $mail->FromName = $defaults['name']; $mail->Sender = $mail->From; /* set Return-Path field in header to reduce spam score in emails sent via Sugar's Email module */ $replyToName = $mail->FromName; $OBCharset = $locale->getPrecedentPreference('default_email_charset'); if (!empty($replyToAddress)) { $mail->AddReplyTo($replyToAddress, $locale->translateCharsetMIME(trim($replyToName), 'UTF-8', $OBCharset)); } else { $mail->AddReplyTo($mail->From, $locale->translateCharsetMIME(trim($mail->FromName), 'UTF-8', $OBCharset)); } foreach ($toAddresses as $addr_arr) { if (empty($addr_arr['email'])) { continue; } if (empty($addr_arr['display'])) { $mail->AddAddress($addr_arr['email'], ""); } else { $mail->AddAddress($addr_arr['email'], $locale->translateCharsetMIME(trim($addr_arr['display']), 'UTF-8', $OBCharset)); } } $mail->AddAttachment($attachFilePath, $attachFileName, 'base64', self::getMimeType($attachFileName)); $mail->prepForOutbound(); $mail->Body = $email->decodeDuringSend($mail->Body); $mail->AltBody = $email->decodeDuringSend($mail->AltBody); if (!$mail->Send()) { ob_clean(); $answer['error'] = $app_strings['LBL_EMAIL_ERROR_PREPEND'] . $mail->ErrorInfo; $answer['status'] = false; return $answer; } //TODO check settings if email need save, save $email bean class return $answer; }
function run_action(SugarBean $bean, $params = array(), $in_save = false) { include_once 'modules/EmailTemplates/EmailTemplate.php'; $emailTemp = new EmailTemplate(); $emailTemp->retrieve($params['email_template']); if ($emailTemp->id == '') { return false; } $emails = $this->getEmailsFromParams($bean, $params); if (!isset($emails['to']) || empty($emails['to'])) { return false; } $attachments = $this->getAttachments($emailTemp); if (isset($params['individual_email']) && $params['individual_email']) { foreach ($emails['to'] as $email_to) { $emailTemp = new EmailTemplate(); $emailTemp->retrieve($params['email_template']); $template_override = isset($emails['template_override'][$email_to]) ? $emails['template_override'][$email_to] : array(); $this->parse_template($bean, $emailTemp, $template_override); $this->sendEmail(array($email_to), $emailTemp->subject, $emailTemp->body_html, $emailTemp->body, $bean, $emails['cc'], $emails['bcc'], $attachments); } } else { $this->parse_template($bean, $emailTemp); if ($emailTemp->text_only == '1') { $email_body_html = $emailTemp->body; } else { $email_body_html = $emailTemp->body_html; } return $this->sendEmail($emails['to'], $emailTemp->subject, $email_body_html, $emailTemp->body, $bean, $emails['cc'], $emails['bcc'], $attachments); } return true; }
} // deferred //$r = $focus->db->query("SELECT id, name FROM queues WHERE owner_id = '".$focus->id."'"); //$a = $focus->db->fetchByAssoc($r); //$queue = '<a href="index.php?module=Queues&action=EditView&record='.$a['id'].'">'.$a['name'].'</a>'; $groupName = ''; if ($focus->group_id) { require_once 'modules/Groups/Group.php'; $group = new Group(); $group->retrieve($focus->group_id); $groupName = $group->user_name; } if ($focus->template_id) { require_once 'modules/EmailTemplates/EmailTemplate.php'; $et = new EmailTemplate(); $et->retrieve($focus->template_id); $emailTemplate = $et->name; } else { $emailTemplate = 'None'; } if ($focus->tls == 'tls') { $tls = $app_list_strings['dom_email_bool']['bool_true']; } else { $tls = $app_list_strings['dom_email_bool']['bool_false']; } if ($focus->ssl == 'ssl') { $ssl = $app_list_strings['dom_email_bool']['bool_true']; } else { $ssl = $app_list_strings['dom_email_bool']['bool_false']; } if ($focus->ca == 'validate-cert') {
* technical reasons, the Appropriate Legal Notices must display the words * "Powered by SugarCRM". ********************************************************************************/ /********************************************************************************* * Description: TODO: To be written. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. ********************************************************************************/ require_once 'modules/EmailTemplates/EmailTemplate.php'; $focus = new EmailTemplate(); if ($_REQUEST['from'] == 'DetailView') { if (!isset($_REQUEST['record'])) { sugar_die("A record number must be specified to delete the template."); } $focus->retrieve($_REQUEST['record']); if ($focus->is_used_by_email_marketing()) { echo 'true'; return; } echo 'false'; } else { if ($_REQUEST['from'] == 'ListView') { $returnString = ''; $idArray = explode(',', $_REQUEST['records']); foreach ($idArray as $key => $value) { if ($focus->retrieve($value)) { if ($focus->is_used_by_email_marketing()) { $returnString .= $focus->name . ','; } }
private function sendCreationEmail(aCase $bean, $contact) { require_once "include/SugarPHPMailer.php"; $mailer = new SugarPHPMailer(); $admin = new Administration(); $admin->retrieveSettings(); $mailer->prepForOutbound(); $mailer->setMailerForSystem(); $email_template = new EmailTemplate(); $aop_config = $this->getAOPConfig(); $email_template->retrieve($aop_config['case_creation_email_template_id']); if (!$aop_config['case_creation_email_template_id'] || !$email_template) { $GLOBALS['log']->warn("CaseUpdatesHook: sendCreationEmail template is empty"); return false; } $emailSettings = getPortalEmailSettings(); $text = $this->populateTemplate($email_template, $bean, $contact); $mailer->Subject = $text['subject']; $mailer->Body = $text['body']; $mailer->IsHTML(true); $mailer->AltBody = $text['body_alt']; $mailer->From = $emailSettings['from_address']; $mailer->FromName = $emailSettings['from_name']; $email = $contact->emailAddress->getPrimaryAddress($contact); $mailer->AddAddress($email); if (!$mailer->Send()) { $GLOBALS['log']->info("CaseUpdatesHook: Could not send email: " . $mailer->ErrorInfo); return false; } else { $this->logEmail($email, $mailer, $bean->id); return true; } }
function handleCreateCase($email, $userId) { global $current_user, $mod_strings, $current_language; $mod_strings = return_module_language($current_language, "Emails"); $GLOBALS['log']->debug('In handleCreateCase'); $c = new aCase(); $this->getCaseIdFromCaseNumber($email->name, $c); if (!$this->handleCaseAssignment($email) && $this->isMailBoxTypeCreateCase()) { // create a case $GLOBALS['log']->debug('retrieveing email'); $email->retrieve($email->id); $c = new aCase(); $c->description = $email->description; $c->assigned_user_id = $userId; $c->name = $email->name; $c->status = 'New'; $c->priority = 'P1'; if (!empty($email->reply_to_email)) { $contactAddr = $email->reply_to_email; } else { $contactAddr = $email->from_addr; } $GLOBALS['log']->debug('finding related accounts with address ' . $contactAddr); if ($accountIds = $this->getRelatedId($contactAddr, 'accounts')) { if (sizeof($accountIds) == 1) { $c->account_id = $accountIds[0]; $acct = new Account(); $acct->retrieve($c->account_id); $c->account_name = $acct->name; } // if } // if $c->save(true); $caseId = $c->id; $c = new aCase(); $c->retrieve($caseId); if ($c->load_relationship('emails')) { $c->emails->add($email->id); } // if if ($contactIds = $this->getRelatedId($contactAddr, 'contacts')) { if (!empty($contactIds) && $c->load_relationship('contacts')) { $c->contacts->add($contactIds); } // if } // if $c->email_id = $email->id; $email->parent_type = "Cases"; $email->parent_id = $caseId; // assign the email to the case owner $email->assigned_user_id = $c->assigned_user_id; $email->name = str_replace('%1', $c->case_number, $c->getEmailSubjectMacro()) . " " . $email->name; $email->save(); $GLOBALS['log']->debug('InboundEmail created one case with number: ' . $c->case_number); $createCaseTemplateId = $this->get_stored_options('create_case_email_template', ""); if (!empty($this->stored_options)) { $storedOptions = unserialize(base64_decode($this->stored_options)); } if (!empty($createCaseTemplateId)) { $fromName = ""; $fromAddress = ""; if (!empty($this->stored_options)) { $fromAddress = $storedOptions['from_addr']; $fromName = from_html($storedOptions['from_name']); $replyToName = !empty($storedOptions['reply_to_name']) ? from_html($storedOptions['reply_to_name']) : $fromName; $replyToAddr = !empty($storedOptions['reply_to_addr']) ? $storedOptions['reply_to_addr'] : $fromAddress; } // if $defaults = $current_user->getPreferredEmail(); $fromAddress = !empty($fromAddress) ? $fromAddress : $defaults['email']; $fromName = !empty($fromName) ? $fromName : $defaults['name']; $to[0]['email'] = $contactAddr; // handle to name: address, prefer reply-to if (!empty($email->reply_to_name)) { $to[0]['display'] = $email->reply_to_name; } elseif (!empty($email->from_name)) { $to[0]['display'] = $email->from_name; } $et = new EmailTemplate(); $et->retrieve($createCaseTemplateId); if (empty($et->subject)) { $et->subject = ''; } if (empty($et->body)) { $et->body = ''; } if (empty($et->body_html)) { $et->body_html = ''; } $et->subject = "Re:" . " " . str_replace('%1', $c->case_number, $c->getEmailSubjectMacro() . " " . $c->name); $html = trim($email->description_html); $plain = trim($email->description); $email->email2init(); $email->from_addr = $email->from_addr_name; $email->to_addrs = $email->to_addrs_names; $email->cc_addrs = $email->cc_addrs_names; $email->bcc_addrs = $email->bcc_addrs_names; $email->from_name = $email->from_addr; $email = $email->et->handleReplyType($email, "reply"); $ret = $email->et->displayComposeEmail($email); $ret['description'] = empty($email->description_html) ? str_replace("\n", "\n<BR/>", $email->description) : $email->description_html; $reply = new Email(); $reply->type = 'out'; $reply->to_addrs = $to[0]['email']; $reply->to_addrs_arr = $to; $reply->cc_addrs_arr = array(); $reply->bcc_addrs_arr = array(); $reply->from_name = $fromName; $reply->from_addr = $fromAddress; $reply->reply_to_name = $replyToName; $reply->reply_to_addr = $replyToAddr; $reply->name = $et->subject; $reply->description = $et->body . "<div><hr /></div>" . $email->description; if (!$et->text_only) { $reply->description_html = $et->body_html . "<div><hr /></div>" . $email->description; } $GLOBALS['log']->debug('saving and sending auto-reply email'); //$reply->save(); // don't save the actual email. $reply->send(); } // if } else { if (!empty($email->reply_to_email)) { $contactAddr = $email->reply_to_email; } else { $contactAddr = $email->from_addr; } $this->handleAutoresponse($email, $contactAddr); } }
public function action_sendinvitemails() { global $db; global $sugar_config; global $mod_strings; $id = $_GET['record']; //get event $event = new FP_events(); $event->retrieve($id); $event->load_relationship('fp_events_contacts'); // get related contacts $event->load_relationship('fp_events_prospects_1'); //get related targets $event->load_relationship('fp_events_leads_1'); //get related leads //Count the number of delegates linked to the event that have not yet been invited $query = "SELECT * FROM fp_events_contacts_c WHERE fp_events_contactsfp_events_ida='" . $event->id . "' AND (invite_status='Not Invited' OR invite_status='' OR invite_status IS NULL) AND deleted='0'"; $result = $db->query($query); $contact_count = $db->getRowCount($result); //count contacts $query = "SELECT * FROM fp_events_prospects_1_c WHERE fp_events_prospects_1fp_events_ida='" . $event->id . "' AND (invite_status='Not Invited' OR invite_status='' OR invite_status IS NULL) AND deleted='0'"; $result = $db->query($query); $prospect_count = $db->getRowCount($result); //count targets $query = "SELECT * FROM fp_events_leads_1_c WHERE fp_events_leads_1fp_events_ida='" . $event->id . "' AND (invite_status='Not Invited' OR invite_status='' OR invite_status IS NULL) AND deleted='0'"; $result = $db->query($query); $lead_count = $db->getRowCount($result); //count leads $delegate_count = $contact_count + $prospect_count + $lead_count; //Total up delegates $invite_count = 0; //used to count the number of emails sent $error_count = 0; //used to count the number of failed email attempts //loop through related contacts foreach ($event->fp_events_contacts->getBeans() as $contact) { //Get accept status of contact $query = 'SELECT invite_status FROM fp_events_contacts_c WHERE fp_events_contactsfp_events_ida="' . $event->id . '" AND fp_events_contactscontacts_idb="' . $contact->id . '"'; $status = $db->getOne($query); if ($status == null || $status == '' || $status == 'Not Invited') { $invite_count++; //set email links $event->link = "<a href='" . $sugar_config['site_url'] . "/index.php?entryPoint=responseEntryPoint&event=" . $event->id . "&delegate=" . $contact->id . "&type=c&response=accept'>Accept</a>"; $event->link_declined = "<a href='" . $sugar_config['site_url'] . "/index.php?entryPoint=responseEntryPoint&event=" . $event->id . "&delegate=" . $contact->id . "&type=c&response=decline'>Decline</a>"; //Get the TO name and e-mail address for the message $rcpt_name = $contact->first_name . ' ' . $contact->last_name; $rcpt_email = $contact->email1; $emailTemp = new EmailTemplate(); $emailTemp->disable_row_level_security = true; $emailTemp->retrieve($event->invite_templates); //Use the ID value of the email template record //check email template is set, if not return error if ($emailTemp->id == '') { SugarApplication::appendErrorMessage($mod_strings['LBL_ERROR_MSG_5']); SugarApplication::redirect("index.php?module=FP_events&return_module=FP_events&action=DetailView&record=" . $event->id); die; } //parse the lead varibales first $firstpass = $emailTemp->parse_template_bean($emailTemp->body_html, 'Contacts', $contact); $email_subject = $emailTemp->parse_template_bean($emailTemp->subject, 'FP_events', $event); $email_body = from_html($emailTemp->parse_template_bean($firstpass, 'FP_events', $event)); $alt_emailbody = wordwrap($emailTemp->parse_template_bean($firstpass, 'FP_events', $event), 900); //get attachments $attachmentBean = new Note(); $attachment_list = $attachmentBean->get_full_list('', "parent_type = 'Emails' AND parent_id = '" . $event->invite_templates . "'"); $attachments = array(); if ($attachment_list != null) { foreach ($attachment_list as $attachment) { $attachments[] = $attachment; } } //send the email $send_invite = $this->sendEmail($rcpt_email, $email_subject, $rcpt_name, $email_body, $alt_emailbody, $contact, $attachments); //Send the message, log if error occurs if (!$send_invite) { $GLOBALS['log']->fatal('ERROR: Invite email failed to send to: ' . $rcpt_name . ' at ' . $rcpt_email); $error_count++; } else { //update contact to invites $query = 'UPDATE fp_events_contacts_c SET invite_status="Invited" WHERE fp_events_contactsfp_events_ida="' . $event->id . '" AND fp_events_contactscontacts_idb="' . $contact->id . '"'; $res = $db->query($query); } } } //loop through related targets foreach ($event->fp_events_prospects_1->getBeans() as $target) { //Get accept status of contact $query = 'SELECT invite_status FROM fp_events_prospects_1_c WHERE fp_events_prospects_1fp_events_ida="' . $event->id . '" AND fp_events_prospects_1prospects_idb="' . $target->id . '"'; $status = $db->getOne($query); if ($status == null || $status == '' || $status == 'Not Invited') { $invite_count++; //set email links $event->link = "<a href='" . $sugar_config['site_url'] . "/index.php?entryPoint=responseEntryPoint&event=" . $event->id . "&delegate=" . $target->id . "&type=t&response=accept'>Accept</a>"; $event->link_declined = "<a href='" . $sugar_config['site_url'] . "/index.php?entryPoint=responseEntryPoint&event=" . $event->id . "&delegate=" . $target->id . "&type=t&response=decline'>Decline</a>"; //Get the TO name and e-mail address for the message $rcpt_name = $target->first_name . ' ' . $target->last_name; $rcpt_email = $target->email1; $emailTemp = new EmailTemplate(); $emailTemp->disable_row_level_security = true; $emailTemp->retrieve($event->invite_templates); //Use the ID value of the email template record //parse the lead varibales first $firstpass = $emailTemp->parse_template_bean($emailTemp->body_html, 'Contacts', $target); $email_subject = $emailTemp->parse_template_bean($emailTemp->subject, 'FP_events', $event); $email_body = from_html($emailTemp->parse_template_bean($firstpass, 'FP_events', $event)); $alt_emailbody = wordwrap($emailTemp->parse_template_bean($firstpass, 'FP_events', $event), 900); //get attachments $attachmentBean = new Note(); $attachment_list = $attachmentBean->get_full_list('', "parent_type = 'Emails' AND parent_id = '" . $event->invite_templates . "'"); $attachments = array(); if ($attachment_list != null) { foreach ($attachment_list as $attachment) { $attachments[] = $attachment; } } //send the email $send_invite = $this->sendEmail($rcpt_email, $email_subject, $rcpt_name, $email_body, $alt_emailbody, $target, $attachments); //Send the message, log if error occurs if (!$send_invite) { $GLOBALS['log']->fatal('ERROR: Invite email failed to send to: ' . $rcpt_name . ' at ' . $rcpt_email); $error_count++; } else { //update contact to invites $query = 'UPDATE fp_events_prospects_1_c SET invite_status="Invited" WHERE fp_events_prospects_1fp_events_ida="' . $event->id . '" AND fp_events_prospects_1prospects_idb="' . $target->id . '"'; $res = $db->query($query); } } } //loop through related leads foreach ($event->fp_events_leads_1->getBeans() as $lead) { //Get accept status of contact $query = 'SELECT invite_status FROM fp_events_leads_1_c WHERE fp_events_leads_1fp_events_ida="' . $event->id . '" AND fp_events_leads_1leads_idb="' . $lead->id . '"'; $status = $db->getOne($query); if ($status == null || $status == '' || $status == 'Not Invited') { $invite_count++; //set email links $event->link = "<a href='" . $sugar_config['site_url'] . "/index.php?entryPoint=responseEntryPoint&event=" . $event->id . "&delegate=" . $lead->id . "&type=l&response=accept'>Accept</a>"; $event->link_declined = "<a href='" . $sugar_config['site_url'] . "/index.php?entryPoint=responseEntryPoint&event=" . $event->id . "&delegate=" . $lead->id . "&type=l&response=decline'>Decline</a>"; //Get the TO name and e-mail address for the message $rcpt_name = $lead->first_name . ' ' . $lead->last_name; $rcpt_email = $lead->email1; $emailTemp = new EmailTemplate(); $emailTemp->disable_row_level_security = true; $emailTemp->retrieve($event->invite_templates); //Use the ID value of the email template record //parse the lead varibales first $firstpass = $emailTemp->parse_template_bean($emailTemp->body_html, 'Contacts', $lead); $email_subject = $emailTemp->parse_template_bean($emailTemp->subject, 'FP_events', $event); $email_body = from_html($emailTemp->parse_template_bean($firstpass, 'FP_events', $event)); $alt_emailbody = wordwrap($emailTemp->parse_template_bean($firstpass, 'FP_events', $event), 900); //get attachments $attachmentBean = new Note(); $attachment_list = $attachmentBean->get_full_list('', "parent_type = 'Emails' AND parent_id = '" . $event->invite_templates . "'"); $attachments = array(); if ($attachment_list != null) { foreach ($attachment_list as $attachment) { $attachments[] = $attachment; } } //send the email $send_invite = $this->sendEmail($rcpt_email, $email_subject, $rcpt_name, $email_body, $alt_emailbody, $lead, $attachments); //Send the message, log if error occurs if (!$send_invite) { $GLOBALS['log']->fatal('ERROR: Invite email failed to send to: ' . $rcpt_name . ' at ' . $rcpt_email); $error_count++; } else { //update contact to invites $query = 'UPDATE fp_events_leads_1_c SET invite_status="Invited" WHERE fp_events_leads_1fp_events_ida="' . $event->id . '" AND fp_events_leads_1leads_idb="' . $lead->id . '"'; $res = $db->query($query); } } } //Redirect with error message if all linked contacts have already been invited if ($invite_count == 0) { SugarApplication::appendErrorMessage($mod_strings['LBL_ERROR_MSG_1']); SugarApplication::redirect("index.php?module=FP_events&return_module=FP_events&action=DetailView&record=" . $event->id); } //Redirect if all emails fail to send if ($error_count == $delegate_count) { $_SESSION['user_error_message'] = array(); //clear the error message array SugarApplication::appendErrorMessage($mod_strings['LBL_ERROR_MSG_2'] . $delegate_count); SugarApplication::redirect("index.php?module=FP_events&return_module=FP_events&action=DetailView&record=" . $event->id); } else { if ($error_count > 0 && $error_count <= 10) { //redirect with failed email count. $_SESSION['user_error_message'] = array(); SugarApplication::appendErrorMessage($error_count . $mod_strings['LBL_ERROR_MSG_4']); SugarApplication::redirect("index.php?module=FP_events&return_module=FP_events&action=DetailView&record=" . $event->id); } else { if ($error_count > 10) { $_SESSION['user_error_message'] = array(); SugarApplication::appendErrorMessage($mod_strings['LBL_ERROR_MSG_3']); SugarApplication::redirect("index.php?module=FP_events&return_module=FP_events&action=DetailView&record=" . $event->id); } else { SugarApplication::appendErrorMessage($mod_strings['LBL_SUCCESS_MSG']); SugarApplication::redirect("index.php?module=FP_events&return_module=FP_events&action=DetailView&record=" . $event->id); } } } }
function run_action(SugarBean $bean, $params = array(), $in_save = false) { include_once 'modules/EmailTemplates/EmailTemplate.php'; $emailTemp = new EmailTemplate(); $emailTemp->retrieve($params['email_template']); if ($emailTemp->id == '') { return false; } $this->parse_template($bean, $emailTemp); $attachments = $this->getAttachments($emailTemp); $emails = $this->getEmailsFromParams($bean, $params); if (!isset($emails['to']) || empty($emails['to'])) { return false; } return $this->sendEmail($emails['to'], $emailTemp->subject, $emailTemp->body_html, $emailTemp->body, $bean, $emails['cc'], $emails['bcc'], $attachments); }
/** * Send new password or link to user * * @param string $templateId Id of email template * @param array $additionalData additional params: link, url, password * @return array status: true|false, message: error message, if status = false and message = '' it means that send method has returned false */ public function sendEmailForPassword($templateId, array $additionalData = array()) { global $sugar_config, $current_user; $mod_strings = return_module_language('', 'Users'); $result = array('status' => false, 'message' => ''); $emailTemp = new EmailTemplate(); $emailTemp->disable_row_level_security = true; if ($emailTemp->retrieve($templateId) == '') { $result['message'] = $mod_strings['LBL_EMAIL_TEMPLATE_MISSING']; return $result; } //replace instance variables in email templates $htmlBody = $emailTemp->body_html; $body = $emailTemp->body; if (isset($additionalData['link']) && $additionalData['link'] == true) { $htmlBody = str_replace('$contact_user_link_guid', $additionalData['url'], $htmlBody); $body = str_replace('$contact_user_link_guid', $additionalData['url'], $body); } else { $htmlBody = str_replace('$contact_user_user_hash', $additionalData['password'], $htmlBody); $body = str_replace('$contact_user_user_hash', $additionalData['password'], $body); } // Bug 36833 - Add replacing of special value $instance_url $htmlBody = str_replace('$config_site_url', $sugar_config['site_url'], $htmlBody); $body = str_replace('$config_site_url', $sugar_config['site_url'], $body); $htmlBody = str_replace('$contact_user_user_name', $this->user_name, $htmlBody); $htmlBody = str_replace('$contact_user_pwd_last_changed', TimeDate::getInstance()->nowDb(), $htmlBody); $body = str_replace('$contact_user_user_name', $this->user_name, $body); $body = str_replace('$contact_user_pwd_last_changed', TimeDate::getInstance()->nowDb(), $body); $emailTemp->body_html = $htmlBody; $emailTemp->body = $body; $itemail = $this->emailAddress->getPrimaryAddress($this); //retrieve IT Admin Email //_ppd( $emailTemp->body_html); //retrieve email defaults $emailObj = new Email(); $defaults = $emailObj->getSystemDefaultEmail(); require_once 'include/SugarPHPMailer.php'; $mail = new SugarPHPMailer(); $mail->setMailerForSystem(); //$mail->IsHTML(true); $mail->From = $defaults['email']; $mail->FromName = $defaults['name']; $mail->ClearAllRecipients(); $mail->ClearReplyTos(); $mail->Subject = from_html($emailTemp->subject); if ($emailTemp->text_only != 1) { $mail->IsHTML(true); $mail->Body = from_html($emailTemp->body_html); $mail->AltBody = from_html($emailTemp->body); } else { $mail->Body_html = from_html($emailTemp->body_html); $mail->Body = from_html($emailTemp->body); } if ($mail->Body == '' && $current_user->is_admin) { global $app_strings; $result['message'] = $app_strings['LBL_EMAIL_TEMPLATE_EDIT_PLAIN_TEXT']; return $result; } if ($mail->Mailer == 'smtp' && $mail->Host == '' && $current_user->is_admin) { $result['message'] = $mod_strings['ERR_SERVER_SMTP_EMPTY']; return $result; } $mail->prepForOutbound(); $hasRecipients = false; if (!empty($itemail)) { if ($hasRecipients) { $mail->AddBCC($itemail); } else { $mail->AddAddress($itemail); } $hasRecipients = true; } if ($hasRecipients) { $result['status'] = @$mail->Send(); } if ($result['status'] == true) { $emailObj->team_id = 1; $emailObj->to_addrs = ''; $emailObj->type = 'archived'; $emailObj->deleted = '0'; $emailObj->name = $mail->Subject; $emailObj->description = $mail->Body; $emailObj->description_html = null; $emailObj->from_addr = $mail->From; $emailObj->parent_type = 'User'; $emailObj->date_sent = TimeDate::getInstance()->nowDb(); $emailObj->modified_user_id = '1'; $emailObj->created_by = '1'; $emailObj->status = 'sent'; $emailObj->save(); if (!isset($additionalData['link']) || $additionalData['link'] == false) { $user_hash = strtolower(md5($additionalData['password'])); $this->setPreference('loginexpiration', '0'); $this->setPreference('lockout', ''); $this->setPreference('loginfailed', '0'); $this->savePreferencesToDB(); //set new password $now = TimeDate::getInstance()->nowDb(); $query = "UPDATE {$this->table_name} SET user_hash='{$user_hash}', system_generated_password='******', pwd_last_changed='{$now}' where id='{$this->id}'"; $this->db->query($query, true, "Error setting new password for {$this->user_name}: "); } } return $result; }
//$usr->db->query($q2); $q = "INSERT INTO users_password_link (id, username, date_generated) VALUES('" . $guid . "','" . $_POST['user_name'] . "',' " . $time_now . "' ) "; $usr->db->query($q); } /////// /////////////////////////////////////////////////// /////// Email creation global $sugar_config, $current_user; if (isset($_POST['link']) && $_POST['link'] == '1') { $emailTemp_id = $res['lostpasswordtmpl']; } else { $emailTemp_id = $res['generatepasswordtmpl']; } $emailTemp = new EmailTemplate(); $emailTemp->disable_row_level_security = true; if ($emailTemp->retrieve($emailTemp_id) == '') { echo $mod_strings['LBL_EMAIL_TEMPLATE_MISSING']; $new_pwd = '4'; return; } //replace instance variables in email templates $htmlBody = $emailTemp->body_html; $body = $emailTemp->body; if (isset($_POST['link']) && $_POST['link'] == '1') { $htmlBody = str_replace('$contact_user_link_guid', $url, $htmlBody); $body = str_replace('$contact_user_link_guid', $url, $body); } else { $htmlBody = str_replace('$contact_user_user_hash', $password, $htmlBody); $body = str_replace('$contact_user_user_hash', $password, $body); } // Bug 36833 - Add replacing of special value $instance_url