Exemple #1
0
/**   Function used to send email
 *   $module 		-- current module
 *   $to_email 	-- to email address
 *   $from_name	-- currently loggedin user name
 *   $from_email	-- currently loggedin vtiger_users's email id. you can give as '' if you are not in HelpDesk module
 *   $subject		-- subject of the email you want to send
 *   $contents		-- body of the email you want to send
 *   $cc		-- add email ids with comma seperated. - optional
 *   $bcc		-- add email ids with comma seperated. - optional.
 *   $attachment	-- whether we want to attach the currently selected file or all files.[values = current,all] - optional
 *   $emailid		-- id of the email object which will be used to get the vtiger_attachments
 */
function send_mail($module, $to_email, $from_name, $from_email, $subject, $contents, $cc = '', $bcc = '', $attachment = '', $emailid = '', $logo = '')
{
    global $adb, $log;
    global $root_directory;
    global $HELPDESK_SUPPORT_EMAIL_ID, $HELPDESK_SUPPORT_NAME;
    $uploaddir = $root_directory . "/test/upload/";
    $adb->println("To id => '" . $to_email . "'\nSubject ==>'" . $subject . "'\nContents ==> '" . $contents . "'");
    //Get the email id of assigned_to user -- pass the value and name, name must be "user_name" or "id"(field names of vtiger_users vtiger_table)
    //$to_email = getUserEmailId('id',$assigned_user_id);
    //if module is HelpDesk then from_email will come based on support email id
    if ($from_email == '') {
        //if from email is not defined, then use the useremailid as the from address
        $from_email = getUserEmailId('user_name', $from_name);
    }
    //if the newly defined from email field is set, then use this email address as the from address
    //and use the username as the reply-to address
    $query = "select * from vtiger_systems where server_type=?";
    $params = array('email');
    $result = $adb->pquery($query, $params);
    $from_email_field = $adb->query_result($result, 0, 'from_email_field');
    if (isUserInitiated()) {
        $replyToEmail = $from_email;
    } else {
        $replyToEmail = $from_email_field;
    }
    if (isset($from_email_field) && $from_email_field != '') {
        //setting from _email to the defined email address in the outgoing server configuration
        $from_email = $from_email_field;
    }
    if ($module != "Calendar") {
        $contents = addSignature($contents, $from_name);
    }
    $mail = new PHPMailer();
    setMailerProperties($mail, $subject, $contents, $from_email, $from_name, trim($to_email, ","), $attachment, $emailid, $module, $logo);
    setCCAddress($mail, 'cc', $cc);
    setCCAddress($mail, 'bcc', $bcc);
    if (!empty($replyToEmail)) {
        $mail->AddReplyTo($replyToEmail);
    }
    $mail->ConfirmReadingTo = $mail->From;
    //MSL
    // vtmailscanner customization: If Support Reply to is defined use it.
    global $HELPDESK_SUPPORT_EMAIL_REPLY_ID;
    if ($HELPDESK_SUPPORT_EMAIL_REPLY_ID && $HELPDESK_SUPPORT_EMAIL_ID != $HELPDESK_SUPPORT_EMAIL_REPLY_ID) {
        $mail->AddReplyTo($HELPDESK_SUPPORT_EMAIL_REPLY_ID);
    }
    // END
    // Fix: Return immediately if Outgoing server not configured
    if (empty($mail->Host)) {
        return 0;
    }
    // END
    $mail_status = MailSend($mail);
    if ($mail_status != 1) {
        $mail_error = getMailError($mail, $mail_status, $mailto);
    } else {
        $mail_error = $mail_status;
    }
    return $mail_error;
}
function CustomerCommentFromPortal($entityData)
{
    $adb = PearDatabase::getInstance();
    $data = $entityData->getData();
    $customerWSId = $data['customer'];
    $relatedToWSId = $data['related_to'];
    $relatedToId = explode('x', $relatedToWSId);
    $moduleName = getSalesEntityType($relatedToId[1]);
    if ($moduleName == 'HelpDesk' && !empty($customerWSId)) {
        $ownerIdInfo = getRecordOwnerId($relatedToId[1]);
        if (!empty($ownerIdInfo['Users'])) {
            $ownerId = $ownerIdInfo['Users'];
            $ownerName = getOwnerName($ownerId);
            $toEmail = getUserEmailId('id', $ownerId);
        }
        if (!empty($ownerIdInfo['Groups'])) {
            $ownerId = $ownerIdInfo['Groups'];
            $groupInfo = getGroupName($ownerId);
            $ownerName = $groupInfo[0];
            $toEmail = implode(',', getDefaultAssigneeEmailIds($ownerId));
        }
        $subject = getTranslatedString('LBL_RESPONDTO_TICKETID', $moduleName) . "##" . $relatedToId[1] . "## " . getTranslatedString('LBL_CUSTOMER_PORTAL', $moduleName);
        $contents = getTranslatedString('Dear', $moduleName) . " " . $ownerName . "," . "<br><br>" . getTranslatedString('LBL_CUSTOMER_COMMENTS', $moduleName) . "<br><br>\n\t\t\t\t\t<b>" . $data['commentcontent'] . "</b><br><br>" . getTranslatedString('LBL_RESPOND', $moduleName) . "<br><br>" . getTranslatedString('LBL_REGARDS', $moduleName) . "<br>" . getTranslatedString('LBL_SUPPORT_ADMIN', $moduleName);
        $customerId = explode('x', $customerWSId);
        $result = $adb->pquery("SELECT email FROM vtiger_contactdetails WHERE contactid=?", array($customerId[0]));
        $fromEmail = $adb->query_result($result, 0, 'email');
        send_mail('HelpDesk', $toEmail, '', $fromEmail, $subject, $contents);
    }
}
 public function save($request)
 {
     vimport('~~/modules/Emails/mail.php');
     $currentUser = Users_Record_Model::getCurrentUserModel();
     $from_email = $request->get('from_email_field');
     $to_email = getUserEmailId('id', $currentUser->getId());
     $subject = $this->getSubject();
     $description = $this->getBody();
     // This is added so that send_mail API will treat it as user initiated action
     $olderAction = $_REQUEST['action'];
     $_REQUEST['action'] = 'Save';
     if ($to_email != '') {
         $mail_status = send_mail('Users', $to_email, $currentUser->get('user_name'), $from_email, $subject, $description, '', '', '', '', '', true);
     }
     $_REQUEST['action'] = $olderAction;
     if ($mail_status != 1 && !$this->isDefaultSettingLoaded()) {
         throw new Exception('Error occurred while sending mail');
     }
     return parent::save();
 }
/**   Function used to send email 
 *   $module 		-- current module 
 *   $to_email 	-- to email address 
 *   $from_name	-- currently loggedin user name
 *   $from_email	-- currently loggedin vtiger_users's email id. you can give as '' if you are not in HelpDesk module
 *   $subject		-- subject of the email you want to send
 *   $contents		-- body of the email you want to send
 *   $cc		-- add email ids with comma seperated. - optional 
 *   $bcc		-- add email ids with comma seperated. - optional.
 *   $attachment	-- whether we want to attach the currently selected file or all vtiger_files.[values = current,all] - optional
 *   $emailid		-- id of the email object which will be used to get the vtiger_attachments
 */
function send_mail($module, $to_email, $from_name, $from_email, $subject, $contents, $cc = '', $bcc = '', $attachment = '', $emailid = '', $logo = '')
{
    global $adb, $log;
    global $root_directory;
    global $HELPDESK_SUPPORT_EMAIL_ID, $HELPDESK_SUPPORT_NAME;
    $uploaddir = $root_directory . "/test/upload/";
    $adb->println("To id => '" . $to_email . "'\nSubject ==>'" . $subject . "'\nContents ==> '" . $contents . "'");
    //Get the email id of assigned_to user -- pass the value and name, name must be "user_name" or "id"(field names of vtiger_users vtiger_table)
    //$to_email = getUserEmailId('id',$assigned_user_id);
    //if module is HelpDesk then from_email will come based on support email id
    if ($from_email == '') {
        //$module != 'HelpDesk')
        $from_email = getUserEmailId('user_name', $from_name);
    }
    if ($module != "Calendar") {
        $contents = addSignature($contents, $from_name);
    }
    $mail = new PHPMailer();
    setMailerProperties($mail, $subject, $contents, $from_email, $from_name, trim($to_email, ","), $attachment, $emailid, $module, $logo);
    setCCAddress($mail, 'cc', $cc);
    setCCAddress($mail, 'bcc', $bcc);
    // vtmailscanner customization: If Support Reply to is defined use it.
    global $HELPDESK_SUPPORT_EMAIL_REPLY_ID;
    if ($HELPDESK_SUPPORT_EMAIL_REPLY_ID && $HELPDESK_SUPPORT_EMAIL_ID != $HELPDESK_SUPPORT_EMAIL_REPLY_ID) {
        $mail->AddReplyTo($HELPDESK_SUPPORT_EMAIL_REPLY_ID);
    }
    // END
    // Fix: Return immediately if Outgoing server not configured
    if (empty($mail->Host)) {
        return 0;
    }
    // END
    $mail_status = MailSend($mail);
    if ($mail_status != 1) {
        $mail_error = getMailError($mail, $mail_status, $mailto);
    } else {
        $mail_error = $mail_status;
    }
    return $mail_error;
}
function HelpDesk_notifyOwnerOnTicketChange($entityData)
{
    global $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID;
    $moduleName = $entityData->getModuleName();
    $wsId = $entityData->getId();
    $parts = explode('x', $wsId);
    $entityId = $parts[1];
    $isNew = $entityData->isNew();
    if (!$isNew) {
        $reply = 'Re : ';
    } else {
        $reply = '';
    }
    // SalesPlatform.ru begin
    $subject = ' [ ' . getTranslatedString('Ticket No', $moduleName) . ' ' . $entityData->get('ticket_no') . ' ] ' . $reply . $entityData->get('ticket_title');
    //$subject = $entityData->get('ticket_no') . ' [ '.getTranslatedString('LBL_TICKET_ID', $moduleName)
    //					.' : '.$entityId.' ] '.$reply.$entityData->get('ticket_title');
    // SalesPlatform.ru end
    $email_body = HelpDesk::getTicketEmailContents($entityData, true);
    if (PerformancePrefs::getBoolean('NOTIFY_OWNER_EMAILS', true) === true) {
        //send mail to the assigned to user and the parent to whom this ticket is assigned
        require_once 'modules/Emails/mail.php';
        $wsAssignedUserId = $entityData->get('assigned_user_id');
        $userIdParts = explode('x', $wsAssignedUserId);
        $ownerId = $userIdParts[1];
        $ownerType = vtws_getOwnerType($ownerId);
        if ($ownerType == 'Users') {
            $to_email = getUserEmailId('id', $ownerId);
        }
        if ($ownerType == 'Groups') {
            $to_email = implode(',', getDefaultAssigneeEmailIds($ownerId));
        }
        if ($to_email != '') {
            if ($isNew) {
                $mail_status = send_mail('HelpDesk', $to_email, $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID, $subject, $email_body);
            } else {
                $entityDelta = new VTEntityDelta();
                $statusHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'ticketstatus');
                $solutionHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'solution');
                $ownerHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'assigned_user_id');
                $descriptionHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'description');
                if ($statusHasChanged && $entityData->get('ticketstatus') == "Closed" || $solutionHasChanged || $ownerHasChanged || $descriptionHasChanged) {
                    $mail_status = send_mail('HelpDesk', $to_email, $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID, $subject, $email_body);
                }
            }
            $mail_status_str = $to_email . "=" . $mail_status . "&&&";
        } else {
            $mail_status_str = "'" . $to_email . "'=0&&&";
        }
        if ($mail_status != '') {
            $mail_error_status = getMailErrorString($mail_status_str);
        }
    }
}
 if ($fieldname != 'comments') {
     $modObj->column_fields['comments'] = '';
 }
 $modObj->column_fields[$fieldname] = $fieldvalue;
 $modObj->id = $crmid;
 $modObj->mode = "edit";
 //Added to construct the update log for Ticket history
 $assigned_group_name = getGroupName($_REQUEST['assigned_group_id']);
 $assigntype = $_REQUEST['assigntype'];
 $fldvalue = $modObj->constructUpdateLog($modObj, $modObj->mode, $assigned_group_name, $assigntype);
 $fldvalue = from_html($fldvalue, $modObj->mode == 'edit' ? true : false);
 $modObj->save("HelpDesk");
 global $mod_strings;
 if ($fieldname == "solution" || $fieldname == "comments" || $fieldname == "assigned_user_id" || $fieldname == "ticketstatus" && $fieldvalue == $mod_strings['Closed']) {
     require_once 'modules/Emails/mail.php';
     $user_emailid = getUserEmailId('id', $modObj->column_fields['assigned_user_id']);
     $subject = $modObj->column_fields['ticket_no'] . ' [ ' . $mod_strings['LBL_TICKET_ID'] . ' : ' . $modObj->id . ' ] Re : ' . $modObj->column_fields['ticket_title'];
     $parent_id = $modObj->column_fields['parent_id'];
     if (!empty($parent_id) && $parent_id != 0) {
         $parent_module = getSalesEntityType($parent_id);
         if ($parent_module == 'Contacts') {
             $result = $adb->pquery("select * from vtiger_contactdetails where contactid=?", array($parent_id));
             $emailoptout = $adb->query_result($result, 0, 'emailoptout');
             $contactname = $adb->query_result($result, 0, 'firstname') . ' ' . $adb->query_result($result, 0, 'lastname');
             $parentname = $contactname;
             $contact_mailid = $adb->query_result($result, 0, 'email');
         }
         if ($parent_module == 'Accounts') {
             $result = $adb->pquery("select * from vtiger_account where accountid=?", array($parent_id));
             $emailoptout = $adb->query_result($result, 0, 'emailoptout');
             $parentname = $adb->query_result($result, 0, 'accountname');
Exemple #7
0
        if ($email == '' || $email == 'NULL') {
            $email = $user_info['email2'];
            if ($email == '' || $email == 'NULL') {
                $email = $user_info['yahoo_id'];
            }
        }
        if ($user_email == '') {
            $user_email .= $user_info['first_name'] . " " . $user_info['last_name'] . "<" . $email . ">";
        } else {
            $user_email .= "," . $user_info['first_name'] . " " . $user_info['last_name'] . "<" . $email . ">";
        }
        $email = '';
    }
    $to_email = $user_email;
} else {
    $to_email = getUserEmailId('id', $focus->column_fields["assigned_user_id"]);
}
$cc = $_REQUEST['ccmail'];
$bcc = $_REQUEST['bccmail'];
if ($to_email == '' && $cc == '' && $bcc == '') {
    $adb->println("Mail Error : send_mail function not called because To email id of assigned to user, CC and BCC are empty");
    $mail_status_str = "'" . $to_email . "'=0&&&";
    $errorheader1 = 1;
} else {
    $query1 = "select email1 from vtiger_users where id =?";
    $res1 = $adb->pquery($query1, array($current_user->id));
    $val = $adb->query_result($res1, 0, "email1");
    //	$mail_status = send_mail('Emails',$to_email,$current_user->user_name,'',$_REQUEST['subject'],$_REQUEST['description'],$cc,$bcc,'all',$focus->id);
    $query = 'update vtiger_emaildetails set email_flag ="SENT",from_email =? where emailid=?';
    $adb->pquery($query, array($val, $focus->id));
    //set the errorheader1 to 1 if the mail has not been sent to the assigned to user
        $smarty->assign("CONTACTSID", $contactId);
        $contact_name = "<option value=" . $contactId . ">" . getContactName($contactId) . "</option>";
        $smarty->assign("CONTACTSNAME", $contact_name);
        $account_id = vtlib_purify($_REQUEST['account_id']);
        $account_name = getAccountName($account_id);
    }
}
if (isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') {
    $focus->id = "";
    $focus->mode = '';
}
if (empty($_REQUEST['record']) && $focus->mode != 'edit') {
    setObjectValuesFromRequest($focus);
}
$userDetails = getOtherUserName($current_user->id);
$to_email = getUserEmailId('id', $current_user->id);
$smarty->assign("CURRENTUSERID", $current_user->id);
$disp_view = getView($focus->mode);
if ($disp_view == 'edit_view') {
    $act_data = getBlocks($tab_type, $disp_view, $mode, $focus->column_fields);
} else {
    $act_data = getBlocks($tab_type, $disp_view, $mode, $focus->column_fields, 'BAS');
}
$smarty->assign("BLOCKS", $act_data);
foreach ($act_data as $header => $blockitem) {
    foreach ($blockitem as $row => $data) {
        foreach ($data as $key => $maindata) {
            $uitype[$maindata[2][0]] = $maindata[0][0];
            $fldlabel[$maindata[2][0]] = $maindata[1][0];
            $fldlabel_sel[$maindata[2][0]] = $maindata[1][1];
            $fldlabel_combo[$maindata[2][0]] = $maindata[1][2];
Exemple #9
0
/**   Function used to send email
 *   $module		-- current module
 *   $to_email		-- to email address
 *   $from_name	-- currently loggedin user name
 *   $from_email	-- currently loggedin users's email id. you can give as '' if you are not in HelpDesk module
 *   $subject		-- subject of the email you want to send
 *   $contents		-- body of the email you want to send
 *   $cc			-- add email ids with comma seperated. - optional
 *   $bcc			-- add email ids with comma seperated. - optional.
 *   $attachment	-- whether we want to attach the currently selected file or all files.[values = current,all] - optional
 *   $emailid		-- id of the email object which will be used to get the vtiger_attachments
 */
function send_mail($module, $to_email, $from_name, $from_email, $subject, $contents, $cc = '', $bcc = '', $attachment = '', $emailid = '', $logo = '', $replyto = '')
{
    global $adb, $log, $root_directory, $HELPDESK_SUPPORT_EMAIL_ID, $HELPDESK_SUPPORT_NAME;
    $uploaddir = $root_directory . "/test/upload/";
    $adb->println("To id => '" . $to_email . "'\nSubject ==>'" . $subject . "'\nContents ==> '" . $contents . "'");
    $femail = '';
    if (substr($from_email, 0, 8) == 'FROM:::>') {
        $femail = substr($from_email, 8);
        $from_email = '';
    }
    if (empty($from_name) and !empty($from_email)) {
        $sql = "select user_name from vtiger_users where status='Active' and (email1=? or email2=? or secondaryemail=?)";
        $result = $adb->pquery($sql, array($from_email, $from_email, $from_email));
        if ($result and $adb->num_rows($result) > 0) {
            $from_name = $adb->query_result($result, 0, 0);
        }
    }
    //if module is HelpDesk then from_email will come based on support email id
    if ($from_email == '') {
        //if from email is not defined, then use the useremailid as the from address
        $from_email = getUserEmailId('user_name', $from_name);
    }
    if (empty($from_email)) {
        $from_email = $HELPDESK_SUPPORT_EMAIL_ID;
    }
    //if the newly defined from email field is set, then use this email address as the from address
    //and use the username as the reply-to address
    $query = "select * from vtiger_systems where server_type=?";
    $params = array('email');
    $result = $adb->pquery($query, $params);
    $from_email_field = $adb->query_result($result, 0, 'from_email_field');
    if (empty($replyto)) {
        if (isUserInitiated()) {
            global $current_user;
            $reply_to_secondary = GlobalVariable::getVariable('Users_ReplyTo_SecondEmail', 0, $module, $current_user->id);
            if ($reply_to_secondary == 1) {
                $sql = "select secondaryemail from vtiger_users where id=?";
                $result = $adb->pquery($sql, array($current_user->id));
                $second_email = '';
                if ($result and $adb->num_rows($result) > 0) {
                    $second_email = $adb->query_result($result, 0, 'secondaryemail');
                }
            }
            if (!empty($second_email)) {
                $replyToEmail = $second_email;
            } else {
                $replyToEmail = $from_email;
            }
        } else {
            $replyToEmail = $from_email_field;
        }
    } else {
        $replyToEmail = $replyto;
    }
    if (isset($from_email_field) && $from_email_field != '') {
        //setting from _email to the defined email address in the outgoing server configuration
        $from_email = $from_email_field;
    }
    if ($femail != '') {
        $from_email = $femail;
    }
    if ($module != "Calendar") {
        $contents = addSignature($contents, $from_name);
    }
    $mail = new PHPMailer();
    setMailerProperties($mail, $subject, $contents, $from_email, $from_name, trim($to_email, ","), $attachment, $emailid, $module, $logo);
    setCCAddress($mail, 'cc', $cc);
    setCCAddress($mail, 'bcc', $bcc);
    if (!empty($replyToEmail)) {
        $mail->AddReplyTo($replyToEmail);
    }
    // vtmailscanner customization: If Support Reply to is defined use it.
    global $HELPDESK_SUPPORT_EMAIL_REPLY_ID;
    if ($HELPDESK_SUPPORT_EMAIL_REPLY_ID && $HELPDESK_SUPPORT_EMAIL_ID != $HELPDESK_SUPPORT_EMAIL_REPLY_ID) {
        $mail->AddReplyTo($HELPDESK_SUPPORT_EMAIL_REPLY_ID);
    }
    // END
    // Fix: Return immediately if Outgoing server not configured
    if (empty($mail->Host)) {
        return 0;
    }
    $mail_status = MailSend($mail);
    if ($mail_status != 1) {
        $mail_error = getMailError($mail, $mail_status, $mailto);
    } else {
        $mail_error = $mail_status;
    }
    return $mail_error;
}
Exemple #10
0
/**   Function used to send email
 *   $module 		-- current module
 *   $to_email 	-- to email address
 *   $from_name	-- currently loggedin user name
 *   $from_email	-- currently loggedin vtiger_users's email id. you can give as '' if you are not in HelpDesk module
 *   $subject		-- subject of the email you want to send
 *   $contents		-- body of the email you want to send
 *   $cc		-- add email ids with comma seperated. - optional
 *   $bcc		-- add email ids with comma seperated. - optional.
 *   $attachment	-- whether we want to attach the currently selected file or all vtiger_files.[values = current,all] - optional
 *   $emailid		-- id of the email object which will be used to get the vtiger_attachments
 */
function send_mail($module, $to_email, $from_name, $from_email, $subject, $contents, $cc = '', $bcc = '', $attachment = '', $emailid = '', $logo = '', $useGivenFromEmailAddress = false, $attachmentSrc = array())
{
    $adb = PearDatabase::getInstance();
    $log = vglobal('log');
    $root_directory = vglobal('root_directory');
    global $HELPDESK_SUPPORT_EMAIL_ID, $HELPDESK_SUPPORT_NAME;
    $uploaddir = $root_directory . "/cache/upload/";
    $adb->println("To id => '" . $to_email . "'\nSubject ==>'" . $subject . "'\nContents ==> '" . $contents . "'");
    //Get the email id of assigned_to user -- pass the value and name, name must be "user_name" or "id"(field names of vtiger_users vtiger_table)
    //$to_email = getUserEmailId('id',$assigned_user_id);
    //if module is HelpDesk then from_email will come based on support email id
    if ($from_email == '') {
        //if from email is not defined, then use the useremailid as the from address
        $from_email = getUserEmailId('user_name', $from_name);
    }
    //if the newly defined from email field is set, then use this email address as the from address
    //and use the username as the reply-to address
    $cachedFromEmail = VTCacheUtils::getOutgoingMailFromEmailAddress();
    if ($cachedFromEmail === null) {
        $query = "select from_email_field from vtiger_systems where server_type=?";
        $params = array('email');
        $result = $adb->pquery($query, $params);
        $from_email_field = $adb->query_result($result, 0, 'from_email_field');
        VTCacheUtils::setOutgoingMailFromEmailAddress($from_email_field);
    }
    if (isUserInitiated()) {
        $replyToEmail = $from_email;
    } else {
        $replyToEmail = $from_email_field;
    }
    if (isset($from_email_field) && $from_email_field != '' && !$useGivenFromEmailAddress) {
        //setting from _email to the defined email address in the outgoing server configuration
        $from_email = $from_email_field;
    }
    if ($module != "Calendar") {
        //$contents = addSignature($contents,$from_name); //TODO improved during the reconstruction Signature
        $mail = new PHPMailer();
    }
    setMailerProperties($mail, $subject, $contents, $from_email, $from_name, trim($to_email, ","), $attachment, $emailid, $module, $logo);
    setCCAddress($mail, 'cc', $cc);
    setCCAddress($mail, 'bcc', $bcc);
    if (!empty($replyToEmail)) {
        $mail->AddReplyTo($replyToEmail);
    }
    // vtmailscanner customization: If Support Reply to is defined use it.
    global $HELPDESK_SUPPORT_EMAIL_REPLY_ID;
    if ($HELPDESK_SUPPORT_EMAIL_REPLY_ID && $HELPDESK_SUPPORT_EMAIL_ID != $HELPDESK_SUPPORT_EMAIL_REPLY_ID) {
        $mail->AddReplyTo($HELPDESK_SUPPORT_EMAIL_REPLY_ID);
    }
    // END
    // Fix: Return immediately if Outgoing server not configured
    if (empty($mail->Host)) {
        return 0;
    }
    // END
    if (count($attachmentSrc)) {
        foreach ($attachmentSrc as $name => $src) {
            if (is_array($src)) {
                $mail->AddStringAttachment($src['string'], $src['filename'], $src['encoding'], $src['type']);
            } else {
                $mail->AddAttachment($src, $name);
            }
        }
    }
    $mail_status = MailSend($mail);
    if ($mail_status != 1) {
        $mail_error = getMailError($mail, $mail_status, $mailto);
    } else {
        $mail_error = $mail_status;
    }
    return $mail_error;
}
Exemple #11
0
function sendInvitation($inviteesid, $mode, $subject, $desc)
{
    global $current_user, $mod_strings;
    require_once "modules/Emails/mail.php";
    $invites = $mod_strings['INVITATION'];
    $invitees_array = explode(';', $inviteesid);
    $subject = $invites . ' : ' . $subject;
    $record = $focus->id;
    foreach ($invitees_array as $inviteeid) {
        if ($inviteeid != '') {
            $description = getActivityDetails($desc, $inviteeid, "invite");
            $to_email = getUserEmailId('id', $inviteeid);
            send_mail('Calendar', $to_email, $current_user->user_name, '', $subject, $description);
        }
    }
}
/**	Function to send the Notification mail to the assigned to owner about the entity creation or updation
  *	@param string $module -- module name
  *	@param object $focus  -- reference of the object
**/
function sendNotificationToOwner($module, $focus)
{
    global $log, $app_strings;
    $log->debug("Entering sendNotificationToOwner(" . $module . "," . get_class($focus) . ") method ...");
    require_once "modules/Emails/mail.php";
    global $current_user;
    $ownername = getUserName($focus->column_fields['assigned_user_id']);
    $ownermailid = getUserEmailId('id', $focus->column_fields['assigned_user_id']);
    $recseqnumber = '';
    if ($module == 'Contacts') {
        $objectname = $focus->column_fields['lastname'] . ' ' . $focus->column_fields['firstname'];
        $recseqnumber = $focus->column_fields['contact_no'];
        $mod_name = 'Contact';
        $object_column_fields = array('lastname' => 'Last Name', 'firstname' => 'First Name', 'leadsource' => 'Lead Source', 'department' => 'Department', 'description' => 'Description');
    }
    if ($module == 'Accounts') {
        $objectname = $focus->column_fields['accountname'];
        $recseqnumber = $focus->column_fields['account_no'];
        $mod_name = 'Account';
        $object_column_fields = array('accountname' => 'Account Name', 'rating' => 'Rating', 'industry' => 'Industry', 'accounttype' => 'Account Type', 'description' => 'Description');
    }
    if ($module == 'Potentials') {
        $objectname = $focus->column_fields['potentialname'];
        $recseqnumber = $focus->column_fields['potential_no'];
        $mod_name = 'Potential';
        $object_column_fields = array('potentialname' => 'Potential Name', 'amount' => 'Amount', 'closingdate' => 'Expected Close Date', 'opportunity_type' => 'Type', 'description' => 'Description');
    }
    if ($module == "Accounts" || $module == "Potentials" || $module == "Contacts") {
        //JFV - i18n module name for mail notification
        $mod_name = $app_strings[$mod_name];
        //JFV END
        $description = $app_strings['MSG_DEAR'] . ' ' . $ownername . ',<br><br>';
        if (!empty($recseqnumber)) {
            $recseqnumber = "[{$recseqnumber}]";
        }
        if ($focus->mode == 'edit') {
            $subject = $app_strings['MSG_REGARDING'] . ' ' . $mod_name . ' ' . $app_strings['MSG_UPDATION'] . " {$recseqnumber} " . $objectname;
            $description .= $app_strings['MSG_THE'] . ' ' . $mod_name . ' ' . $app_strings['MSG_HAS_BEEN_UPDATED'] . '.';
        } else {
            $subject = $app_strings['MSG_REGARDING'] . ' ' . $mod_name . ' ' . $app_strings['MSG_ASSIGNMENT'] . " {$recseqnumber} " . $objectname;
            $description .= $app_strings['MSG_THE'] . ' ' . $mod_name . ' ' . $app_strings['MSG_HAS_BEEN_ASSIGNED_TO_YOU'] . '.';
        }
        $description .= '<br>' . $app_strings['MSG_THE'] . ' ' . $mod_name . ' ' . $app_strings['MSG_DETAILS_ARE'] . ':<br><br>';
        $description .= $mod_name . ' ' . $app_strings['MSG_ID'] . ' ' . '<b>' . $focus->id . '</b><br>';
        foreach ($object_column_fields as $fieldname => $fieldlabel) {
            //Get the translated string
            $temp_label = isset($app_strings[$fieldlabel]) ? $app_strings[$fieldlabel] : (isset($mod_strings[$fieldlabel]) ? $mod_strings[$fieldlabel] : $fieldlabel);
            $description .= $temp_label . ' : <b>' . $focus->column_fields[$fieldname] . '</b><br>';
        }
        $description .= '<br><br>' . $app_strings['MSG_THANK_YOU'] . ',<br>' . $current_user->user_name . '.<br>';
        $status = send_mail($module, $ownermailid, $current_user->user_name, '', $subject, $description);
        $log->debug("Exiting sendNotificationToOwner method ...");
        return $status;
    }
}
Exemple #13
0
/**	function used to create ticket which has been created from customer portal
 *	@param array $input_array - array which contains the following values
 => 	int $id - customer id
	int $sessionid - session id
	string $title - title of the ticket
	string $description - description of the ticket
	string $priority - priority of the ticket
	string $severity - severity of the ticket
	string $category - category of the ticket
	string $user_name - customer name
	int $parent_id - parent id ie., customer id as this customer is the parent for this ticket
	int $product_id - product id for the ticket
	string $module - module name where as based on this module we will get the module owner and assign this ticket to that corresponding user
	*	return array - currently created ticket array, if this is not created then all tickets list will be returned
	*/
function create_ticket($input_array)
{
    global $adb, $log;
    $adb->println("Inside customer portal function create_ticket");
    $adb->println($input_array);
    $id = $input_array['id'];
    $sessionid = $input_array['sessionid'];
    $title = $input_array['title'];
    $description = $input_array['description'];
    $priority = $input_array['priority'];
    $severity = $input_array['severity'];
    $category = $input_array['category'];
    $user_name = $input_array['user_name'];
    $parent_id = (int) $input_array['parent_id'];
    $product_id = (int) $input_array['product_id'];
    $module = $input_array['module'];
    //$assigned_to = $input_array['assigned_to'];
    $servicecontractid = $input_array['serviceid'];
    $projectid = $input_array['projectid'];
    if (!validateSession($id, $sessionid)) {
        return null;
    }
    $ticket = new HelpDesk();
    $ticket->column_fields[ticket_title] = $title;
    $ticket->column_fields[description] = $description;
    $ticket->column_fields[ticketpriorities] = $priority;
    $ticket->column_fields[ticketseverities] = $severity;
    $ticket->column_fields[ticketcategories] = $category;
    $ticket->column_fields[ticketstatus] = 'Open';
    $ticket->column_fields[parent_id] = $parent_id;
    $ticket->column_fields[product_id] = $product_id;
    $userid = getPortalUserid();
    $ticket->column_fields['assigned_user_id'] = $userid;
    $ticket->save("HelpDesk");
    $subject = "[From Portal] " . $ticket->column_fields['ticket_no'] . " [ Ticket ID : {$ticket->id} ] " . $title;
    $contents = ' Ticket No : ' . $ticket->column_fields['ticket_no'] . '<br> Ticket ID : ' . $ticket->id . '<br> Ticket Title : ' . $title . '<br><br>' . $description;
    //get the contact email id who creates the ticket from portal and use this email as from email id in email
    $result = $adb->pquery("select email from vtiger_contactdetails where contactid=?", array($parent_id));
    $contact_email = $adb->query_result($result, 0, 'email');
    $from_email = $contact_email;
    //send mail to assigned to user
    $to_email = getUserEmailId('id', $userid);
    $adb->println("Send mail to the user who is the owner of the module about the portal ticket");
    $mail_status = send_mail('HelpDesk', $to_email, '', $from_email, $subject, $contents);
    //send mail to the customer(contact who creates the ticket from portal)
    $adb->println("Send mail to the customer(contact) who creates the portal ticket");
    $mail_status = send_mail('Contacts', $contact_email, '', $from_email, $subject, $contents);
    $ticketresult = $adb->pquery("select vtiger_troubletickets.ticketid from vtiger_troubletickets\n\t\tinner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_troubletickets.ticketid inner join vtiger_ticketcf on vtiger_ticketcf.ticketid = vtiger_troubletickets.ticketid \n\t\twhere vtiger_crmentity.deleted=0 and vtiger_troubletickets.ticketid = ?", array($ticket->id));
    if ($adb->num_rows($ticketresult) == 1) {
        $record_save = 1;
        $record_array[0]['new_ticket']['ticketid'] = $adb->query_result($ticketresult, 0, 'ticketid');
    }
    if ($servicecontractid != '') {
        $res = $adb->pquery("insert into vtiger_crmentityrel values(?,?,?,?)", array($servicecontractid, 'ServiceContracts', $ticket->id, 'HelpDesk'));
    }
    if ($projectid != '') {
        $res = $adb->pquery("insert into vtiger_crmentityrel values(?,?,?,?)", array($projectid, 'Project', $ticket->id, 'HelpDesk'));
    }
    if ($record_save == 1) {
        $adb->println("Ticket from Portal is saved with id => " . $ticket->id);
        return $record_array;
    } else {
        $adb->println("There may be error in saving the ticket.");
        return null;
    }
}
Exemple #14
0
/**   Function used to send email
 *   $module 		-- current module
 *   $to_email 	-- to email address
 *   $from_name	-- currently loggedin user name
 *   $from_email	-- currently loggedin vtiger_users's email id. you can give as '' if you are not in HelpDesk module
 *   $subject		-- subject of the email you want to send
 *   $contents		-- body of the email you want to send
 *   $cc		-- add email ids with comma seperated. - optional
 *   $bcc		-- add email ids with comma seperated. - optional.
 *   $attachment	-- whether we want to attach the currently selected file or all vtiger_files.[values = current,all] - optional
 *   $emailid		-- id of the email object which will be used to get the vtiger_attachments
 */
function send_mail($module, $to_email, $from_name, $from_email, $subject, $contents, $cc = '', $bcc = '', $attachment = '', $emailid = '', $logo = '', $useGivenFromEmailAddress = false)
{
    global $adb, $log;
    global $root_directory;
    global $HELPDESK_SUPPORT_EMAIL_ID, $HELPDESK_SUPPORT_NAME;
    global $WERPASCOPETESTUPLOAD;
    $uploaddir = $root_directory . "{$WERPASCOPETESTUPLOAD}/";
    $adb->println("To id => '" . $to_email . "'\nSubject ==>'" . $subject . "'\nContents ==> '" . $contents . "'");
    //Get the email id of assigned_to user -- pass the value and name, name must be "user_name" or "id"(field names of vtiger_users vtiger_table)
    //$to_email = getUserEmailId('id',$assigned_user_id);
    //if module is HelpDesk then from_email will come based on support email id
    if ($from_email == '') {
        //if from email is not defined, then use the useremailid as the from address
        $from_email = getUserEmailId('user_name', $from_name);
    }
    //if the newly defined from email field is set, then use this email address as the from address
    //and use the username as the reply-to address
    $cachedFromEmail = VTCacheUtils::getOutgoingMailFromEmailAddress();
    if ($cachedFromEmail === null) {
        $query = "select from_email_field from vtiger_systems where server_type=?";
        $params = array('email');
        $result = $adb->pquery($query, $params);
        $from_email_field = $adb->query_result($result, 0, 'from_email_field');
        VTCacheUtils::setOutgoingMailFromEmailAddress($from_email_field);
    }
    if (isUserInitiated()) {
        $replyToEmail = $from_email;
    } else {
        $replyToEmail = $from_email_field;
    }
    if (isset($from_email_field) && $from_email_field != '' && !$useGivenFromEmailAddress) {
        //setting from _email to the defined email address in the outgoing server configuration
        $from_email = $from_email_field;
    }
    if ($module != "Calendar") {
        $contents = addSignature($contents, $from_name);
    }
    $mail = new PHPMailer();
    setMailerProperties($mail, $subject, $contents, $from_email, $from_name, trim($to_email, ","), $attachment, $emailid, $module, $logo);
    setCCAddress($mail, 'cc', $cc);
    setCCAddress($mail, 'bcc', $bcc);
    // SalesPlatform.ru begin
    // Duplicated AddReplyTo() call. First into the setMailerProperties()
    //if(!empty($replyToEmail)) {
    //	$mail->AddReplyTo($replyToEmail);
    //}
    // SalesPlatform.ru end
    // vtmailscanner customization: If Support Reply to is defined use it.
    global $HELPDESK_SUPPORT_EMAIL_REPLY_ID;
    if ($HELPDESK_SUPPORT_EMAIL_REPLY_ID && $HELPDESK_SUPPORT_EMAIL_ID != $HELPDESK_SUPPORT_EMAIL_REPLY_ID) {
        $mail->AddReplyTo($HELPDESK_SUPPORT_EMAIL_REPLY_ID);
    }
    // END
    // Fix: Return immediately if Outgoing server not configured
    if (empty($mail->Host)) {
        return 0;
    }
    // END
    $mail_status = MailSend($mail);
    if ($mail_status != 1) {
        $mail_error = getMailError($mail, $mail_status, $mailto);
    } else {
        $mail_error = $mail_status;
        // SalesPlatform.ru begin corrected date of sending
        $query = 'UPDATE vtiger_emaildetails SET email_flag ="SENT" WHERE emailid=?';
        $adb->pquery($query, array($emailid));
        // SalesPlatform.ru end
    }
    return $mail_error;
}