/** Function to set all the Mailer properties * $mail -- reference of the mail object * $subject -- subject of the email you want to send * $contents -- body of the email you want to send * $from_email -- from email id which will be displayed in the mail * $from_name -- from name which will be displayed in the mail * $to_email -- to email address -- This can be an email in a single string, a comma separated * list of emails or an array of email addresses * $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 - optional */ function setMailerProperties($mail, $subject, $contents, $from_email, $from_name, $to_email, $attachment = '', $emailid = '', $module = '', $logo = '') { global $adb; $adb->println("Inside the function setMailerProperties"); if ($module == "Support" || $logo == 1) { $mail->AddEmbeddedImage('themes/images/logo_mail.jpg', 'logo', 'logo.jpg', "base64", "image/jpg"); } $mail->Subject = $subject; $mail->Body = $contents; //$mail->Body = html_entity_decode(nl2br($contents)); //if we get html tags in mail then we will use this line $mail->AltBody = strip_tags(preg_replace(array("/<p>/i", "/<br>/i", "/<br \\/>/i"), array("\n", "\n", "\n"), $contents)); $mail->IsSMTP(); //set mailer to use SMTP //$mail->Host = "smtp1.example.com;smtp2.example.com"; // specify main and backup server setMailServerProperties($mail); //Handle the from name and email for HelpDesk $mail->From = $from_email; $rs = $adb->pquery("select first_name,last_name from vtiger_users where user_name=?", array($from_name)); if ($adb->num_rows($rs) > 0) { $from_name = $adb->query_result($rs, 0, "first_name") . " " . $adb->query_result($rs, 0, "last_name"); } $mail->FromName = decode_html($from_name); if ($to_email != '') { if (is_array($to_email)) { for ($j = 0, $num = count($to_email); $j < $num; $j++) { $mail->addAddress($to_email[$j]); } } else { $_tmp = explode(",", $to_email); for ($j = 0, $num = count($_tmp); $j < $num; $j++) { $mail->addAddress($_tmp[$j]); } } } $mail->AddReplyTo($from_email); $mail->WordWrap = 50; //If we want to add the currently selected file only then we will use the following function if ($attachment == 'current' && $emailid != '') { if (isset($_REQUEST['filename_hidden'])) { $file_name = $_REQUEST['filename_hidden']; } else { $file_name = $_FILES['filename']['name']; } addAttachment($mail, $file_name, $emailid); } //This will add all the vtiger_files which are related to this record or email if ($attachment == 'all' && $emailid != '') { addAllAttachments($mail, $emailid); } $mail->IsHTML(true); // set email format to HTML return; }
/** * @param $context \Workflow\VTEntity * @return mixed */ public function handleTask(&$context) { global $adb, $current_user; global $current_language; if (defined("WF_DEMO_MODE") && constant("WF_DEMO_MODE") == true) { return "yes"; } if (!class_exists("Workflow_PHPMailer")) { require_once "modules/Workflow2/phpmailer/class.phpmailer.php"; } #$result = $adb->query("select user_name, email1, email2 from vtiger_users where id=1"); #$from_email = "*****@*****.**"; #$from_name = "Stefan Warnat"; $module = $context->getModuleName(); $et = new \Workflow\VTTemplate($context); $to_email = $et->render(trim($this->get("recepient")), ","); # $connected = $this->getConnectedObjects("Absender"); if (count($connected) > 0) { $from_name = trim($connected[0]->get("first_name") . " " . $connected[0]->get("last_name")); $from_email = $connected[0]->get("email1"); } else { $from_name = $et->render(trim($this->get("from_name")), ","); # $from_email = $et->render(trim($this->get("from_mail")), ","); # } $cc = $et->render(trim($this->get("emailcc")), ","); # $bcc = $et->render(trim($this->get("emailbcc")), ","); # /** * Connected BCC Objects * @var $connected */ $connected = $this->getConnectedObjects("BCC"); $bccs = $connected->get("email1"); if (count($bccs) > 0) { $bcc = array($bcc); foreach ($bccs as $bccTMP) { $bcc[] = $bccTMP; } $bcc = trim(implode(",", $bcc), ","); } if (strlen(trim($to_email, " \t\n,")) == 0 && strlen(trim($cc, " \t\n,")) == 0 && strlen(trim($bcc, " \t\n,")) == 0) { return "yes"; } $storeid = trim($this->get("storeid", $context)); if (empty($storeid) || $storeid == -1 || !is_numeric($storeid)) { $storeid = $context->getId(); } $embeddedImages = array(); $content = $this->get("content"); $subject = $this->get("subject"); #$subject = utf8_decode($subject); #$content = utf8_encode($content); $content = html_entity_decode(str_replace(" ", " ", $content), ENT_QUOTES, "UTF-8"); #$subject = html_entity_decode(str_replace(" ", " ", $subject), ENT_QUOTES, "UTF-8"); $subject = $et->render(trim($subject)); $content = $et->render(trim($content)); $mailtemplate = $this->get("mailtemplate"); if (!empty($mailtemplate) && $mailtemplate != -1) { if (strpos($mailtemplate, 's#') === false) { $sql = "SELECT * FROM vtiger_emailtemplates WHERE templateid = " . intval($mailtemplate); $result = $adb->query($sql); $mailtemplate = $adb->fetchByAssoc($result); $content = str_replace('$mailtext', $content, html_entity_decode($mailtemplate["body"], ENT_COMPAT, 'UTF-8')); $content = Vtiger_Functions::getMergedDescription($content, $context->getId(), $context->getModuleName()); } else { $parts = explode('#', $mailtemplate); switch ($parts[1]) { case 'emailmaker': $templateid = $parts[2]; $sql = 'SELECT body, subject FROM vtiger_emakertemplates WHERE templateid = ?'; $result = $adb->pquery($sql, array($templateid)); $EMAILContentModel = \EMAILMaker_EMAILContent_Model::getInstance($this->getModuleName(), $context->getId(), $current_language, $context->getId(), $this->getModuleName()); $EMAILContentModel->setSubject($adb->query_result($result, 0, 'subject')); $EMAILContentModel->setBody($adb->query_result($result, 0, 'body')); $EMAILContentModel->getContent(true); $embeddedImages = $EMAILContentModel->getEmailImages(); $subject = $EMAILContentModel->getSubject(); $content = $EMAILContentModel->getBody(); break; } } } #$content = htmlentities($content, ENT_NOQUOTES, "UTF-8"); if (getTabid('Emails') && vtlib_isModuleActive('Emails')) { require_once 'modules/Emails/Emails.php'; $focus = new Emails(); $focus->column_fields["assigned_user_id"] = \Workflow\VTEntity::getUser()->id; $focus->column_fields["activitytype"] = "Emails"; $focus->column_fields["date_start"] = date("Y-m-d"); $focus->column_fields["parent_id"] = $storeid; $focus->column_fields["email_flag"] = "SAVED"; $focus->column_fields["subject"] = $subject; $focus->column_fields["description"] = $content; $focus->column_fields["from_email"] = $from_email; $focus->column_fields["saved_toid"] = '["' . str_replace(',', '","', trim($to_email, ",")) . '"]'; $focus->column_fields["ccmail"] = $cc; $focus->column_fields["bccmail"] = $bcc; $focus->save("Emails"); $this->_mailRecord = $focus; #error_log("eMail:".$emailID); $emailID = $focus->id; } else { $emailID = ""; } $attachments = json_decode($this->get("attachments"), true); if (is_array($attachments) && count($attachments) > 0) { // Module greifen auf Datenbank zurück. Daher vorher speichern! $context->save(); foreach ($attachments as $key => $value) { if ($value == false) { continue; } if (is_string($value)) { $value = array($value, false, array()); } // legacy check if (strpos($key, 'document#') === 0) { $key = 's#' . $key; } if (strpos($key, 's#') === 0) { $tmpParts = explode('#', $key, 2); $specialAttachments = \Workflow\Attachment::getAttachments($tmpParts[1], $value, $context, \Workflow\Attachment::MODE_NOT_ADD_NEW_ATTACHMENTS); foreach ($specialAttachments as $attachment) { if ($attachment[0] === 'ID') { $this->attachByAttachmentId($attachment[1]); } elseif ($attachment[0] === 'PATH') { $this->attachFile($attachment[1], $attachment[2], $attachment[3]); } } } else { $file = \Workflow\InterfaceFiles::getFile($key, $this->getModuleName(), $context->getId()); $this->attachFile($file['path'], $value[1] != false ? $value[1] : $file['name'], $file['type']); } } } $receiver = explode(",", $to_email); foreach ($receiver as $to_email) { $to_email = trim($to_email); if (empty($to_email)) { continue; } if (DEMO_MODE == false) { // Self using $mail = new Workflow_PHPMailer(); $mail->CharSet = 'utf-8'; $mail->IsSMTP(); foreach ($embeddedImages as $cid => $cdata) { $mail->AddEmbeddedImage($cdata["path"], $cid, $cdata["name"]); } setMailServerProperties($mail); $to_email = trim($to_email, ","); #setMailerProperties($mail,$subject, $content, $from_email, $from_name, trim($to_email,","), "all", $emailID); $mail->Timeout = 60; $mail->FromName = $from_name; $mail->From = $from_email; $this->addStat("From: " . $from_name . " <" . $from_email . ">"); if ($this->get('trackAccess') == '1') { //Including email tracking details global $site_URL, $application_unique_key; $counterUrl = $site_URL . '/modules/Emails/actions/TrackAccess.php?parentId=' . $storeid . '&record=' . $focus->id . '&applicationKey=' . $application_unique_key; $counterHeight = 1; $counterWidth = 1; if (defined('TRACKING_IMG_HEIGHT')) { $counterHeight = TRACKING_IMG_HEIGHT; } if (defined('TRACKING_IMG_WIDTH')) { $counterWidth = TRACKING_IMG_WIDTH; } $content = "<img src='" . $counterUrl . "' alt='' width='" . $counterWidth . "' height='" . $counterHeight . "'>" . $content; } $mail->Subject = $subject; $this->addStat("Subject: " . $subject); $mail->MsgHTML($content); $mail->SMTPDebug = 2; $mail->addAddress($to_email); $this->addStat("To: " . $to_email); setCCAddress($mail, 'cc', $cc); setCCAddress($mail, 'bcc', $bcc); #$mail->IsHTML(true); addAllAttachments($mail, $emailID); try { ob_start(); $mail_return = MailSend($mail); $debug = ob_get_clean(); $this->addStat($debug); } catch (Workflow_phpmailerException $exp) { Workflow2::error_handler($exp->getCode(), $exp->getMessage(), $exp->getFile(), $exp->getLine()); } #$mail_return = send_mail($module, $to_email,$from_name,$from_email,$subject,$content, $cc, $bcc,'all',$emailID); } else { $mail_return = 1; } $this->addStat("Send eMail with following Result:"); $this->addStat($mail_return); if ($mail_return != 1) { if (empty($mail->ErrorInfo) && empty($mail_return)) { $mail_return = 1; } } $context->setEnvironment("sendmail_result", $mail_return, $this); if ($mail_return != 1) { if ($this->isContinued()) { $delay = 180; } else { $delay = 60; } Workflow2::send_error("Sendmail Task couldn't send an email to " . $to_email . "<br>Error: " . var_export($mail->ErrorInfo, true) . "<br><br>The Task will be rerun after " . $delay . " minutes.", __FILE__, __LINE__); Workflow2::error_handler(E_NONBREAK_ERROR, "Sendmail Task couldn't send an email to " . $to_email . "<br>Error: " . var_export($mail->ErrorInfo, true) . "<br><br>The Task will be rerun after " . $delay . " minutes.", __FILE__, __LINE__); return array("delay" => time() + $delay * 60, "checkmode" => "static"); } } // Set Mails as Send $sql = "UPDATE vtiger_emaildetails SET email_flag = 'SENT' WHERE emailid = '" . $emailID . "'"; $adb->query($sql); return "yes"; }
/** Function to set all the Mailer properties * $mail -- reference of the mail object * $subject -- subject of the email you want to send * $contents -- body of the email you want to send * $from_email -- from email id which will be displayed in the mail * $from_name -- from name which will be displayed in the mail * $to_email -- to email address -- This can be an email in a single string, a comma separated * list of emails or an array of email addresses * $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 - optional */ function setMailerProperties($mail, $subject, $contents, $from_email, $from_name, $to_email, $attachment = '', $emailid = '', $module = '', $logo = '') { $adb = PearDatabase::getInstance(); $adb->println("Inside the function setMailerProperties"); $CompanyDetails = getCompanyDetails(); $logourl = 'storage/Logo/' . $CompanyDetails['logoname']; if ($logo == 1) { $image = getimagesize($logourl); $mail->AddEmbeddedImage($logourl, 'logo', $CompanyDetails['logoname'], "base64", $image['mime']); } $mail->Subject = $subject; //Added back as we have changed php mailer library, older library was using html_entity_decode before sending mail $mail->Body = decode_html($contents); //$mail->Body = html_entity_decode(nl2br($contents)); //if we get html tags in mail then we will use this line $mail->AltBody = strip_tags(preg_replace(array("/<p>/i", "/<br>/i", "/<br \\/>/i"), array("\n", "\n", "\n"), $contents)); $mail->IsSMTP(); //set mailer to use SMTP //$mail->Host = "smtp1.example.com;smtp2.example.com"; // specify main and backup server setMailServerProperties($mail); //Handle the from name and email for HelpDesk $mail->From = $from_email; $userFullName = trim(VTCacheUtils::getUserFullName($from_name)); if (empty($userFullName)) { $rs = $adb->pquery("select first_name,last_name from vtiger_users where user_name=?", array($from_name)); $num_rows = $adb->num_rows($rs); if ($num_rows > 0) { $fullName = getFullNameFromQResult($rs, 0, 'Users'); VTCacheUtils::setUserFullName($from_name, $fullName); } } else { $from_name = $userFullName; } $mail->FromName = decode_html($from_name); if ($to_email != '') { if (is_array($to_email)) { for ($j = 0, $num = count($to_email); $j < $num; $j++) { $mail->addAddress($to_email[$j]); } } else { $_tmp = explode(",", $to_email); for ($j = 0, $num = count($_tmp); $j < $num; $j++) { $mail->addAddress($_tmp[$j]); } } } //commented so that it does not add from_email in reply to //$mail->AddReplyTo($from_email); $mail->WordWrap = 50; //If we want to add the currently selected file only then we will use the following function if ($attachment == 'current' && $emailid != '') { if (isset($_REQUEST['filename_hidden'])) { $file_name = $_REQUEST['filename_hidden']; } else { $file_name = $_FILES['filename']['name']; } addAttachment($mail, $file_name, $emailid); } //This will add all the vtiger_files which are related to this record or email if ($attachment == 'all' && $emailid != '') { addAllAttachments($mail, $emailid); } $mail->IsHTML(true); // set email format to HTML return; }
/** Function to set all the Mailer properties * $mail -- reference of the mail object * $subject -- subject of the email you want to send * $contents -- body of the email you want to send * $from_email -- from email id which will be displayed in the mail * $from_name -- from name which will be displayed in the mail * $to_email -- to email address -- This can be an email in a single string, a comma separated * list of emails or an array of email addresses * $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 - optional */ function setMailerProperties($mail, $subject, $contents, $from_email, $from_name, $to_email, $attachment = '', $emailid = '', $module = '', $logo = '') { global $adb; $adb->println("Inside the function setMailerProperties"); if ($module == "Support" || $logo == 1) { $mail->AddEmbeddedImage('layouts/vlayout/skins/images/logo_mail.jpg', 'logo', 'logo.jpg', "base64", "image/jpg"); } // SalesPlatform.ru begin $mail->Timeout = 20; // SalesPlatform.ru end $mail->Subject = $subject; //Added back as we have changed php mailer library, older library was using html_entity_decode before sending mail $mail->Body = decode_html($contents); //$mail->Body = html_entity_decode(nl2br($contents)); //if we get html tags in mail then we will use this line $mail->AltBody = strip_tags(preg_replace(array("/<p>/i", "/<br>/i", "/<br \\/>/i"), array("\n", "\n", "\n"), $contents)); // SalesPlatform.ru begin $query = "select * from vtiger_systems where server_type=?"; $params = array('email'); $result = $adb->pquery($query, $params); if (isset($_REQUEST['use_sendmail'])) { $use_sendmail = $_REQUEST['use_sendmail']; if ($use_sendmail == 'on') { $use_sendmail = 'true'; } } else { if (isset($_REQUEST['module']) && $_REQUEST['module'] == 'Settings' && !isset($_REQUEST['use_sendmail'])) { //added to avoid issue while editing the values in the outgoing mail server. $use_sendmail = 'false'; } else { $use_sendmail = $adb->query_result($result, 0, 'use_sendmail'); } } if ($use_sendmail == "true" || $use_sendmail == "on") { $mail->IsSendmail(); } else { $mail->IsSMTP(); } // $mail->IsSMTP(); //set mailer to use SMTP // SalesPlatform.ru end //$mail->Host = "smtp1.example.com;smtp2.example.com"; // specify main and backup server setMailServerProperties($mail); // SalesPlatform.ru begin $idn = new idna_convert(); // SalesPlatform.ru end //Handle the from name and email for HelpDesk // SalesPlatform.ru begin $mail->From = $idn->encode($from_email); $from_name_db = $adb->query_result($result, 0, 'from_name'); if (isset($from_name_db) && $from_name_db != '') { //setting from _email to the defined email address in the outgoing server configuration $from_name = $from_name_db; } else { $rs = $adb->pquery("select first_name,last_name from vtiger_users where user_name=?", array($from_name)); $num_rows = $adb->num_rows($rs); if ($num_rows > 0) { $from_name = getFullNameFromQResult($rs, 0, 'Users'); } } // SalesPlatform.ru end $mail->From = $from_email; $userFullName = trim(VTCacheUtils::getUserFullName($from_name)); if (empty($userFullName)) { $rs = $adb->pquery("select first_name,last_name from vtiger_users where user_name=?", array($from_name)); $num_rows = $adb->num_rows($rs); if ($num_rows > 0) { $fullName = getFullNameFromQResult($rs, 0, 'Users'); VTCacheUtils::setUserFullName($from_name, $fullName); } } else { $from_name = $userFullName; } $mail->FromName = decode_html($from_name); if ($to_email != '') { if (is_array($to_email)) { for ($j = 0, $num = count($to_email); $j < $num; $j++) { // SalesPlatform.ru begin $mail->addAddress($idn->encode($to_email[$j])); // $mail->addAddress($to_email[$j]); // SalesPlatform.ru end } } else { $_tmp = explode(",", $to_email); for ($j = 0, $num = count($_tmp); $j < $num; $j++) { // SalesPlatform.ru begin $mail->addAddress($idn->encode($_tmp[$j])); // $mail->addAddress($_tmp[$j]); // SalesPlatform.ru end } } } //commented so that it does not add from_email in reply to //$mail->AddReplyTo($from_email); $mail->WordWrap = 50; //If we want to add the currently selected file only then we will use the following function if ($attachment == 'current' && $emailid != '') { if (isset($_REQUEST['filename_hidden'])) { $file_name = $_REQUEST['filename_hidden']; } else { $file_name = $_FILES['filename']['name']; } addAttachment($mail, $file_name, $emailid); } //This will add all the vtiger_files which are related to this record or email if ($attachment == 'all' && $emailid != '') { addAllAttachments($mail, $emailid); } // SalesPlatform.ru begin // Support for plain filename attachments if ($attachment != '' && $attachment != 'current' && $attachment != 'all') { addAttachment($mail, $attachment, $emailid); } // SalesPlatform.ru end $mail->IsHTML(true); // set email format to HTML return; }