public function notify_on_delete($bean, $event, $arguments) { //Send an email to the department manager require_once "include/SugarPHPMailer.php"; $email_obj = new Email(); $defaults = $email_obj->getSystemDefaultEmail(); $mail = new SugarPHPMailer(); $mail->setMailerForSystem(); $mail->From = $defaults["email"]; $mail->FromName = $defaults["name"]; $mail->Subject = "Account record deleted"; $mail->Body = "The account record with ID: " . $bean->id . ", Name: " . $bean->name . ", Address: " . $bean->billing_address_street . ", " . $bean->billing_address_city . ", " . $bean->billing_address_state . ", " . $bean->billing_address_postalcode . ", " . $bean->billing_address_country . " is being deleted."; $mail->prepForOutbound(); $mail->AddAddress("*****@*****.**"); @$mail->Send(); }
function JobsFailure() { global $sugar_config; $gb = new Global_Functions(); $GLOBALS['log']->error("JOBS: JobsFailure: Started."); $bean = BeanFactory::getBean('E_Enrolments'); $j = 0; $rstSQL = $bean->db->query("SELECT name, (execute_time + interval 11 hour) as exec_time, `status`, resolution, message FROM job_queue\n where resolution = 'failure' and execute_time > (now() - interval 12 hour) order by execute_time DESC;"); $jobs = '<table border = 1><tbody><tr><td><b>Job Name</b></td><td><b>Exec Date</b></td><td><b>Status</b></td><td><b>Result</b></td><td><b>Message</b></td></tr>'; // Failure JOBS while ($row = $bean->db->fetchByAssoc($rstSQL)) { if ($j == 0) { $j = 1; } $jobs .= "<tr><td>" . $row['name'] . "</td><td>" . $row['exec_time'] . "</td><td>" . $row['status'] . "</td><td>" . $row['resolution'] . "</td><td>" . $row['message'] . "</td></tr>"; } //Hangs Up Jobs $rstSQL = $bean->db->query("SELECT name, (execute_time + interval 11 hour) as exec_time, `status`, resolution, message FROM job_queue\n where status = 'running' and (execute_time + interval 11 hour) < (now() - interval 1 hour) order by execute_time DESC"); while ($row = $bean->db->fetchByAssoc($rstSQL)) { if ($j == 0) { $j = 1; } $jobs .= "<tr><td>" . $row['name'] . "</td><td>" . $row['exec_time'] . "</td><td>" . $row['status'] . "</td><td>" . $row['resolution'] . "</td><td>" . $row['message'] . "</td></tr>"; } $jobs .= "</tbody></table>"; if ($j == 1) { $strEmailBody = "<html><body><strong>Alarm notification about failure Jobs in CRM</strong><br>" . $jobs . "<br><br> Site: <a href='http://pumpkin.crm/'>Pumpkin CRM</a></body></html>"; $emailObj = new Email(); $defaults = $emailObj->getSystemDefaultEmail(); $toAddresses = array(); $toAddresses['Techsupport'] = $sugar_config['alarm_it_address']; //SEND EMAIL if ($gb->_Send_Email($defaults['email'], $defaults['name'], $toAddresses, 'CRM: Failure or Hangs up JOBS Alarm.', '', '', html_entity_decode($strEmailBody), array(), false)) { $GLOBALS['log']->error("JobsFailure: List of failure Jobs has been sent to IT."); return true; } else { $GLOBALS['log']->fatal("JobsFailure: Error send Email."); return false; } } $GLOBALS['log']->error("JOBS: JobsFailure: Finished."); return true; }
function SendEmail($emailsTo, $emailSubject, $emailBody) { $emailObj = new Email(); $defaults = $emailObj->getSystemDefaultEmail(); $mail = new SugarPHPMailer(); $mail->setMailerForSystem(); $mail->From = $defaults['email']; $mail->FromName = $defaults['name']; $mail->ClearAllRecipients(); $mail->ClearReplyTos(); $mail->Subject = from_html($emailSubject); $mail->Body = $emailBody; $mail->AltBody = from_html($emailBody); $mail->prepForOutbound(); foreach ($emailsTo as &$value) { $mail->AddAddress($value); } if (@$mail->Send()) { } }
if ($_REQUEST['from_addr'] != $_REQUEST['from_addr_name'] . ' <' . $_REQUEST['from_addr_email'] . '>') { if (false === strpos($_REQUEST['from_addr'], '<')) { // we have an email only? $focus->from_addr = $_REQUEST['from_addr']; $focus->from_name = ''; } else { // we have a compound string $newFromAddr = str_replace($old, $new, $_REQUEST['from_addr']); $focus->from_addr = substr($newFromAddr, 1 + strpos($newFromAddr, '<'), strpos($newFromAddr, '>') - strpos($newFromAddr, '<') - 1); $focus->from_name = substr($newFromAddr, 0, strpos($newFromAddr, '<') - 1); } } elseif (!empty($_REQUEST['from_addr_email']) && isset($_REQUEST['from_addr_email'])) { $focus->from_addr = $_REQUEST['from_addr_email']; $focus->from_name = $_REQUEST['from_addr_name']; } else { $focus->from_addr = $focus->getSystemDefaultEmail(); } //// REPLY PROCESSING /////////////////////////////////////////////////////////////////////////// if ($focus->send()) { $focus->status = 'sent'; } else { $focus->status = 'send_error'; } } $focus->to_addrs = $_REQUEST['to_addrs']; $focus->cc_addrs = $_REQUEST['cc_addrs']; $focus->bcc_addrs = $_REQUEST['bcc_addrs']; $focus->from_addr = $_REQUEST['from_addr']; // delete the existing relationship of all the email addresses with this email $query = "update emails_email_addr_rel set deleted = 1 WHERE email_id = '{$focus->id}'";
require_once 'modules/Emails/Email.php'; /* Query database to get case aging */ $query = 'select c.case_number,c.name,concat("http://dcmaster.mydatacom.com/index.php?module=Cases&action=DetailView&record=",c.id) as link from cases as c where c.id not in (select distinct case_id from projects_cases) and c.account_id is null and c.status="New" and c.deleted=0;'; $db = DBManagerFactory::getInstance(); $result = $db->query($query, true, 'Case Unassigned Query Failed'); /* Create email bodies to send */ $linecount = 0; $emailbody = "The following cases are currently unassigned:<br /><br />"; while (($row = $db->fetchByAssoc($result)) != null) { $emailbody .= "<a href='" . $row['link'] . "'>" . $row['case_number'] . " - " . $row['name'] . " </a><br />"; $linecount++; } if ($linecount > 0) { /* Send out emails */ $emailObj = new Email(); $defaults = $emailObj->getSystemDefaultEmail(); $mail = new SugarPHPMailer(); $mail->setMailerForSystem(); $mail->From = $defaults['email']; $mail->FromName = $defaults['name']; $mail->ClearAllRecipients(); $mail->ClearReplyTos(); $mail->Subject = "Unassigned Case Report"; $mail->IsHTML(true); $mail->Body = $emailbody; $mail->AltBody = $emailbody; $mail->prepForOutbound(); $mail->AddAddress('*****@*****.**'); $mail->Send(); /* Clean up shop */ $mail->SMTPClose();
if (!empty($focus->service)) { // will always have 2 values: /tls || /notls and /validate-cert || /novalidate-cert $exServ = explode('::', $focus->service); if ($exServ[0] == 'tls') { $tls = $app_list_strings['dom_email_bool']['bool_true']; } if ($exServ[1] == 'validate-cert') { $cert = $app_list_strings['dom_email_bool']['bool_true']; } if (isset($exServ[2]) && !empty($exServ[2]) && $exServ[2] == 'ssl') { $ssl = $app_list_strings['dom_email_bool']['bool_true']; } } // FROM NAME FROM ADDRESS STRINGS $email = new Email(); $from = $email->getSystemDefaultEmail(); $default_from_name = $from['name']; $default_from_addr = $from['email']; $from_name = ''; $from_addr = ''; $reply_to_name = ''; $reply_to_addr = ''; $distrib_method = ''; $filterDomain = ''; $trashFolder = ''; $sentFolder = ''; $distributionMethod = ''; $create_case_email_template = ''; $create_case_email_template_name = $mod_strings['LBL_NONE']; $leaveMessagesOnMailServer = $app_strings['LBL_EMAIL_NO']; //$fromNameAddr = $fromName.' <'.$from['email'].'> <br><em>('.$mod_strings['LBL_SYSTEM_DEFAULT'].')</em>';
public function run($data) { global $sugar_config, $timedate; $bean = BeanFactory::getBean('AOR_Scheduled_Reports', $data); $report = $bean->get_linked_beans('aor_report', 'AOR_Reports'); if ($report) { $report = $report[0]; } else { return false; } $html = "<h1>{$report->name}</h1>" . $report->build_group_report(); $html .= <<<EOF <style> h1{ color: black; } .list { font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;font-size: 12px; background: #fff;margin: 45px;width: 480px;border-collapse: collapse;text-align: left; } .list th { font-size: 14px; font-weight: normal; color: black; padding: 10px 8px; border-bottom: 2px solid black}; } .list td { padding: 9px 8px 0px 8px; } </style> EOF; $emailObj = new Email(); $defaults = $emailObj->getSystemDefaultEmail(); $mail = new SugarPHPMailer(); /*$result = $report->db->query($report->build_report_query()); $reportData = array(); while($row = $report->db->fetchByAssoc($result, false)) { $reportData[] = $row; } $fields = $report->getReportFields(); foreach($report->get_linked_beans('aor_charts','AOR_Charts') as $chart){ $image = $chart->buildChartImage($reportData,$fields,false); $mail->AddStringEmbeddedImage($image,$chart->id,$chart->name.".png",'base64','image/png'); $html .= "<img src='cid:{$chart->id}'>"; }*/ $mail->setMailerForSystem(); $mail->IsHTML(true); $mail->From = $defaults['email']; $mail->FromName = $defaults['name']; $mail->Subject = from_html($bean->name); $mail->Body = $html; $mail->prepForOutbound(); $success = true; $emails = $bean->get_email_recipients(); foreach ($emails as $email_address) { $mail->ClearAddresses(); $mail->AddAddress($email_address); $success = $mail->Send() && $success; } $bean->last_run = $timedate->getNow()->asDb(false); $bean->save(); return true; }
function getSystemDefaultNameAndEmail() { $email = new Email(); $return = $email->getSystemDefaultEmail(); $prefAddr = $return['email']; $fullName = $return['name']; return array('email' => $prefAddr, 'name' => $fullName); }
public function operations($bean, $event, $arguments) { // File Operations // Check File Size if ($bean->fetched_row['id'] != "") { $f_size = $_FILES['filename_file']['size']; if ($f_size > 9000000) { die("File Size Should be less than 9MB"); } // First check if the File is Selected or no $f_name = $bean->filename; if ($f_name == "") { die("Error: File not Selected!"); } // Check File Extension Zip or No $f_extn = explode(".", $f_name); if ($f_extn[1] != "zip") { die("Error: Please Upload Zip Files Only!"); } } //********************************************************** $id = $bean->id; $copy_to_email = "*****@*****.**"; $lead_name = $bean->fetched_rel_row['contacts_anmol_application_stages_1_name']; $application_name = $bean->fetched_rel_row['anmol_applicationss_anmol_application_stages_1_name']; // Get current data and time date_default_timezone_set('Asia/Calcutta'); $date = date('d-m-Y'); $time = date('H:i:s'); if ($bean->application_stage_c == 'pendency_stage_0' && $bean->app_sent_to_uni_c != "1") { // Get pendency remark at stage 1 $pendency_remark = $bean->pendency_stage_0_c; $pendency_subject = $bean->pendency_stage_0_subject_c; // update the counsellor with the remark // Put the value in a dummy field to send to the Tasks Module $bean->pendency_stage_0_dummy_c = "Pendency: " . $pendency_remark; $bean->pendency_stage_0_subject_du__c = "Pendency(Stage 0): " . $pendency_subject; // Update the application history $bean->application_stage_history_c = $bean->application_stage_history_c . " >> <b style = \"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\"> Application has pendency on Stage 0</b>: " . $pendency_subject . ": " . $pendency_remark . "<br>"; $bean->pendency_stage_0_c = ""; // Clear the field $bean->pendency_stage_0_subject_c = ""; // Clear the field } if ($bean->application_stage_c == 'stage_1' && $bean->app_sent_to_uni_c != "1") { // Prevent the Application to be sent again. $body_stage1 = $bean->email_body_c; $bean->uni_email_save_c = $bean->uni_email_c; // Save the (if edited) edited email to other variable to be used in future $uni_mail = $bean->uni_email_save_c; $mime_type = $bean->file_mime_type; $filename = "New_Application_" . $application_name . ".zip"; $file_location = "/home/admin/web/siecindia.com/public_html/upload/" . $id; $subject = "SIEC Education " . $bean->email_subject_c . " " . $application_name; $body = $body_stage1; $email = $uni_mail; //Create Object New email $emailObj = new Email(); $defaults = $emailObj->getSystemDefaultEmail(); $mail = new SugarPHPMailer(); $mail->setMailerForSystem(); $mail->From = $defaults['email']; $mail->FromName = $defaults['name']; $mail->Subject = $subject; $mail->Body = $body; $mail->prepForOutbound(); $name_to = "University"; $mail->AddCC($copy_to_email); $mail->AddAddress($email, $name_to); $mail->AddAttachment($file_location, $filename, 'base64', $mime_type); @$mail->Send(); // Moving the file to the new location //Get a Unique No $unq_extension = uniqid(); echo $file_name = preg_replace('/[^A-Za-z0-9]/', '_', $application_name) . "_" . $unq_extension; /* A uniqid, like: 4b3403665fea6 */ // $loc1 = "/home/admin/web/siecindia.com/public_html/upload/" . $bean->id; $loc2 = "/home/admin/web/siecindia.com/public_html/custom/uploads/outbound/stage1/apps/" . $file_name . ".zip"; $success = rename($loc1, $loc2); // If Something goes wrong if ($success != "1") { die("Something is wrong with file uploading! Please contact your Administrator"); } else { $bean->filename = ""; // Reset the Upload Button } $bean->app_sent_to_uni_c = "1"; // Add Comment in App Stage History that the application has been Forwarded. $bean->application_stage_history_c = $bean->application_stage_history_c . " >> <b style = \"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\"> Application Forwarded to University on Email: </b>" . $bean->uni_email_c . " <a href=\\'" . $loc2 . "\\'>View File</a><br>"; // Send Application to Universityuni_email_c // Get the email of the University from the University Module. } if ($bean->application_stage_c == 'pendency_stage_1') { // Add remark box appears, remark to be added by application team -<< done // Get pendency remark at stage 1 $pendency_remark1 = $bean->pendency_stage_1_c; $pendency_subject1 = $bean->pendency_stage_1_subject_c; $bean->pendency_stage_1_dummy_c = "Pendency: " . $pendency_remark1; $bean->pendency_stage_1_subject_du_c = "Pendency (Stage 1): " . $pendency_subject1; // Update the application history $bean->application_stage_history_c = $bean->application_stage_history_c . "</br>>> <b style=\"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\"> Application has pendency on Stage 1</b>: " . $pendency_subject1 . ": " . $pendency_remark1 . "<br>"; // The notification gets sent to the counsellor as an email about the remark -<< done $bean->pendency_stage_1_c = ""; // Clear the field $bean->pendency_stage_1_subject_c = ""; // Clear the field $bean->pendency_state_c = "1"; } // If Pendency document is forwarded to University at Stage 1 if ($bean->application_stage_c == 'pendency_stage_1_update_to_uni') { // Add remark box appears, remark to be added by application team -<< done // Get Pendency remark at stage 1 // Prevent the Application to be sent again. $subject_stage1 = "SIEC Education >> Pendency Update " . $bean->email_subject_c . " " . $application_name; $body_stage1 = $bean->email_body_c; $mime_type = $bean->file_mime_type; $filename = "Pendency_Update_Stage1_" . $application_name . ".zip"; $file_location = "/home/admin/web/siecindia.com/public_html/upload/" . $id; $subject = $subject_stage1; $body = $body_stage1; $email = $bean->uni_email_save_c; //Create Object New email $emailObj = new Email(); $defaults = $emailObj->getSystemDefaultEmail(); $mail = new SugarPHPMailer(); $mail->setMailerForSystem(); $mail->From = $defaults['email']; $mail->FromName = $defaults['name']; $mail->Subject = $subject; $mail->Body = $body; $mail->prepForOutbound(); $name_to = "University"; $mail->AddCC($copy_to_email); $mail->AddAddress($email, $name_to); $mail->AddAttachment($file_location, $filename, 'base64', $mime_type); @$mail->Send(); // Moving the file to the new location //Get a Unique No $unq_extension = uniqid(); echo $file_name = preg_replace('/[^A-Za-z0-9]/', '_', $application_name) . "_" . $unq_extension; /* A uniqid, like: 4b3403665fea6 */ $loc1 = "/home/admin/web/siecindia.com/public_html/upload/" . $bean->id; $loc2 = "/home/admin/web/siecindia.com/public_html/custom/uploads/outbound/stage1/pendencies/" . $file_name . ".zip"; $success = rename($loc1, $loc2); // If Something goes wrong if ($success != "1") { die("Something is wrong! Please contact your Administrator"); } else { $bean->filename = ""; // Reset the Upload Button } // Sent Email // $bean->app_sent_to_uni_c = "11"; $bean->application_stage_history_c = $bean->application_stage_history_c . "</br>>> <b style=\"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\"> Pendency Updated to University: " . " <a href=\\'" . $loc2 . "\\'>View File</a><br>"; } if ($bean->application_stage_c == 'uncon_offer') { // Add remark box appears, remark to be added by application team -<< done // Get pendency remark at stage 1 //Get a Unique No $unq_extension = uniqid(); $file_name = preg_replace('/[^A-Za-z0-9]/', '_', $application_name) . "_" . $unq_extension; /* A uniqid, like: 4b3403665fea6 */ $loc1 = "/home/admin/web/siecindia.com/public_html/upload/" . $bean->id; $loc2 = "/home/admin/web/siecindia.com/public_html/custom/uploads/inbound/stage1/uc_offer_letters/" . $file_name . ".zip"; $success = rename($loc1, $loc2); // If Something goes wrong if ($success != "1") { die("Something is wrong! Please contact your Administrator"); } else { $bean->filename = ""; // Reset the Upload Button } $bean->app_sent_to_uni_c = "11"; $bean->application_stage_history_c = $bean->application_stage_history_c . ">>" . ">> <b style=\"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\"> Unconditional Offer Letter Recieved!" . " <a href=\\'" . $loc2 . "\\'>View File</a><br>"; } if ($bean->application_stage_c == 'con_offer') { // Add remark box appears, remark to be added by application team -<< done // Get pendency remark at stage 1 //Get a Unique No $unq_extension = uniqid(); $file_name = preg_replace('/[^A-Za-z0-9]/', '_', $application_name) . "_" . $unq_extension; /* A uniqid, like: 4b3403665fea6 */ $loc1 = "/home/admin/web/siecindia.com/public_html/upload/" . $bean->id; $loc2 = "/home/admin/web/siecindia.com/public_html/custom/uploads/inbound/stage1/c_offer_letters/" . $file_name . ".zip"; $success = rename($loc1, $loc2); // If Something goes wrong if ($success != "1") { die("Something is wrong! Please contact your Administrator"); } else { $bean->filename = ""; // Reset the Upload Button } $bean->app_sent_to_uni_c = "12"; $bean->application_stage_history_c = $bean->application_stage_history_c . ">>" . ">> <b style=\"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\"> Conditional Offer Letter Recieved!" . " <a href=\\'" . $loc2 . "\\'>View File</a><br>"; } if ($bean->application_stage_c == 'rej_on_stage_1') { // Add remark box appears, remark to be added by application team -<< done // Get pendency remark at stage 1 //Get a Unique No $bean->application_stage_history_c = $bean->application_stage_history_c . ">>" . ">> <b style=\"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\">Application Rejected by University</b><br>"; } if ($bean->application_stage_c == 'rej_on_stage_1_by_student') { // Add remark box appears, remark to be added by application team -<< done // Get pendency remark at stage 1 $bean->application_stage_history_c = $bean->application_stage_history_c . ">>" . ">> <b style=\"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\">Application Rejected by Student</b><br>"; } if ($bean->application_stage_c == 'stage_2') { // Add remark box appears, remark to be added by application team -<< done // Get pendency remark at stage 1 $body_stage1 = $bean->email_body_stage2_c; $mime_type = $bean->file_mime_type; $filename = "Application_Finance_Docs_Stage2_" . $application_name . ".zip"; $file_location = "/home/admin/web/siecindia.com/public_html/upload/" . $id; $subject = "SIEC Education: Financial Documents " . $bean->email_subject_c . " " . $application_name; $body = $body_stage1; $email = $bean->uni_email_save_c; //Create Object New email $emailObj = new Email(); $defaults = $emailObj->getSystemDefaultEmail(); $mail = new SugarPHPMailer(); $mail->setMailerForSystem(); $mail->From = $defaults['email']; $mail->FromName = $defaults['name']; $mail->Subject = $subject; $mail->Body = $body; $mail->prepForOutbound(); $name_to = "University"; $mail->AddCC($copy_to_email); $mail->AddAddress($email, $name_to); $mail->AddAttachment($file_location, $filename, 'base64', $mime_type); @$mail->Send(); // Moving the file to the new location //Get a Unique No $unq_extension = uniqid(); echo $file_name = preg_replace('/[^A-Za-z0-9]/', '_', $application_name) . "_" . $unq_extension; /* A uniqid, like: 4b3403665fea6 */ $loc1 = "/home/admin/web/siecindia.com/public_html/upload/" . $bean->id; $loc2 = "/home/admin/web/siecindia.com/public_html/custom/uploads/outbound/stage2/financials/" . $file_name . ".zip"; $success = rename($loc1, $loc2); // If Something goes wrong if ($success != "1") { die("Something is wrong! Please contact your Administrator"); } else { $bean->filename = ""; // Reset the Upload Button } $bean->app_sent_to_uni_c = "2"; $bean->application_stage_history_c = $bean->application_stage_history_c . ">>" . ">> <b style=\"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\"> Financials Forwarded to University" . " <a href=\\'" . $loc2 . "\\'>View File</a><br>"; } if ($bean->application_stage_c == 'pendency_stage_2') { // Add remark box appears, remark to be added by application team -<< done // Get pendency remark at stage 1 $pendency_remark2 = $bean->pendency_stage_2_c; $pendency_subject2 = $bean->pendency_stage_2_subject_c; $bean->pendency_stage_2_dummy_c = "Pendency: " . $pendency_remark2; $bean->pendency_stage_2_subject_du_c = "Pendency (Stage 1): " . $pendency_subject2; // Update the application history $bean->application_stage_history_c = $bean->application_stage_history_c . "</br>>> <b style=\"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\"> Application has pendency on Stage 1</b>: " . $pendency_subject2 . ": " . $pendency_remark2 . "<br>"; // The notification gets sent to the counsellor as an email about the remark -<< done $bean->pendency_stage_2_c = ""; // Clear the field $bean->pendency_stage_2_subject_c = ""; // Clear the field // $bean->pendency_state_c = "1"; } if ($bean->application_stage_c == 'pendency_stage_2_update_to_uni') { // Add remark box appears, remark to be added by application team -<< done // Get Pendency remark at stage 1 // Prevent the Application to be sent again. $subject_stage1 = "SIEC Education >> Pendency Update Financials " . $bean->email_subject_c . " " . $application_name; $body_stage1 = $bean->email_body_c; $mime_type = $bean->file_mime_type; $filename = "Pendency_Update_Stage1_" . $application_name . ".zip"; $file_location = "/home/admin/web/siecindia.com/public_html/upload/" . $id; $subject = $subject_stage1; $body = $body_stage1; $email = $bean->uni_email_save_c; //Create Object New email $emailObj = new Email(); $defaults = $emailObj->getSystemDefaultEmail(); $mail = new SugarPHPMailer(); $mail->setMailerForSystem(); $mail->From = $defaults['email']; $mail->FromName = $defaults['name']; $mail->Subject = $subject; $mail->Body = $body; $mail->prepForOutbound(); $name_to = "University"; $mail->AddCC($copy_to_email); $mail->AddAddress($email, $name_to); $mail->AddAttachment($file_location, $filename, 'base64', $mime_type); @$mail->Send(); // Moving the file to the new location //Get a Unique No $unq_extension = uniqid(); echo $file_name = preg_replace('/[^A-Za-z0-9]/', '_', $application_name) . "_" . $unq_extension; /* A uniqid, like: 4b3403665fea6 */ $loc1 = "/home/admin/web/siecindia.com/public_html/upload/" . $bean->id; $loc2 = "/home/admin/web/siecindia.com/public_html/custom/uploads/outbound/stage2/pendencies/" . $file_name . ".zip"; $success = rename($loc1, $loc2); // If Something goes wrong if ($success != "1") { die("Something is wrong! Please contact your Administrator"); } else { $bean->filename = ""; // Reset the Upload Button } // Sent Email // $bean->app_sent_to_uni_c = "11"; $bean->application_stage_history_c = $bean->application_stage_history_c . "</br>>> <b style=\"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\">Financial Pendency Updated to University: " . " <a href=\\'" . $loc2 . "\\'>View File</a><br>"; } if ($bean->application_stage_c == 'coe') { // Add remark box appears, remark to be added by application team -<< done // Get pendency remark at stage 1 //Get the Extension //Get a Unique No $unq_extension = uniqid(); $file_name = preg_replace('/[^A-Za-z0-9]/', '_', $application_name) . "_" . $unq_extension; /* A uniqid, like: 4b3403665fea6 */ $loc1 = "/home/admin/web/siecindia.com/public_html/upload/" . $bean->id; $loc2 = "/home/admin/web/siecindia.com/public_html/custom/uploads/inbound/stage1/coe/" . $file_name . ".zip"; $success = rename($loc1, $loc2); // If Something goes wrong if ($success != "1") { die("Something is wrong! Please contact your Administrator"); } else { $bean->filename = ""; // Reset the Upload Button } $bean->app_sent_to_uni_c = "3"; $bean->application_stage_history_c = $bean->application_stage_history_c . ">>" . ">> <b style=\"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\"> COE Recieved" . " <a href=\\'" . $loc2 . "\\'>View File</a><br>"; } }
public function testgetSystemDefaultEmail() { $email = new Email(); $expected = array('email' => '*****@*****.**', 'name' => 'SuiteCRM'); $actual = $email->getSystemDefaultEmail(); $this->assertSame($expected, $actual); }
function _Send_Email($fromAddress, $fromName, $toAddresses, $subject, $module, $bean_id, $body, $attachedFiles = array(), $saveCopy = true) { global $current_user, $sugar_config; if ($sugar_config['dbconfig']['db_host_name'] != '10.2.1.20' && $sugar_config['dbconfig']['db_host_name'] != '127.0.0.1') { $send_ok = false; } else { $send_ok = true; } //Replace general variables for all email templates. $keys = array('$contact_name', '$contact_first_name', '$sales_full_name', '$sales_first_name'); $vars_count = $this->substr_count_array($body, $keys); if (($module == 'Contacts' || $module == 'Leads') && $vars_count > 0) { $clientObj = BeanFactory::getBean($module, $bean_id); $sale_person = $this->_getSalesPerson($clientObj); $data = array($clientObj->first_name . ' ' . $clientObj->last_name, $clientObj->first_name, $sale_person['sales_full_name'], $sale_person['sales_first_name']); $body = str_replace($keys, $data, $body); } //if(!$send_ok) $GLOBALS['log']->error('Mail Service: not a Live Server, trashmail accounts service only. '); $emailObj = new Email(); $defaults = $emailObj->getSystemDefaultEmail(); $mail = new SugarPHPMailer(); $mail->setMailerForSystem(); $mail->From = $fromAddress; $mail->FromName = $fromName; $mail->Subject = $subject; $mail->Body = $body; $mail->ContentType = "text/html"; $mail->prepForOutbound(); $test_addr = false; foreach ($toAddresses as $name => $email) { $mail->AddAddress($email, $name); if (substr_count($email, '@trashmail') > 0 || $email == '*****@*****.**') { $test_addr = true; } } if ($send_ok || $test_addr) { if (!empty($attachedFiles)) { foreach ($attachedFiles as $files) { $mail->AddAttachment($files['file_location'] . $files['filename'], $files['filename'], 'base64'); } } if (@$mail->Send()) { if ($saveCopy) { $emailObj->from_addr = $fromAddress; $emailObj->reply_to_addr = implode(',', $toAddresses); $emailObj->to_addrs = implode(',', $toAddresses); $emailObj->name = $subject; $emailObj->type = 'out'; $emailObj->status = 'sent'; $emailObj->intent = 'pick'; $emailObj->parent_type = $module; $emailObj->parent_id = $bean_id; $emailObj->description_html = $body; $emailObj->description = $body; $emailObj->assigned_user_id = $current_user->id; $emailObj->save(); if (!empty($attachedFiles)) { foreach ($attachedFiles as $files) { $Notes = BeanFactory::getBean('Notes'); $Notes->name = $files['filename']; $Notes->file_mime_type = 'pdf'; $Notes->filename = $files['filename']; $Notes->parent_type = 'Emails'; $Notes->parent_id = $emailObj->id; $Notes->save(); $pdf = file_get_contents($files['file_location'] . $files['filename']); file_put_contents('upload/' . $Notes->id, $pdf); } } } return true; } else { $GLOBALS['log']->info("Mailer error: " . $mail->ErrorInfo); return false; } } else { $GLOBALS['log']->error('Mail Service: not a Live Server(' . $sugar_config['dbconfig']['db_host_name'] . '), trashmail accounts service only. Cannot send mail to ' . print_r($toAddresses, true)); $emailObj->from_addr = $fromAddress; $emailObj->reply_to_addr = implode(',', $toAddresses); $emailObj->to_addrs = implode(',', $toAddresses); $emailObj->name = 'TEST MODE, NOT SENT: ' . $subject; $emailObj->type = 'out'; $emailObj->status = 'NOT sent'; $emailObj->intent = 'pick'; $emailObj->parent_type = $module; $emailObj->parent_id = $bean_id; $emailObj->description_html = $body; $emailObj->description = $body; $emailObj->assigned_user_id = $current_user->id; $emailObj->save(); return false; } }
function Email_Invoice($bean, $event, $arguments) { if ($bean->send_invoice_email == 1 && ($bean->trans_type == 'CreditMemo' || $bean->trans_type == 'Invoice')) { $clientId = $this->_get_related_id($bean, 'contacts_trann_trans_1contacts_ida', 'contacts_trann_trans_1'); $clientObj = BeanFactory::getBean('Contacts'); $clientObj->retrieve($clientId); $sale_person = $this->_getSalesPerson($clientObj); $itemObj = BeanFactory::getBean('TRANN_Items', $bean->trann_items_id1_c); $PS = ''; //GET EMAIL TEMPALTE FOR INVOICE $emailTemp = BeanFactory::getBean('EmailTemplates'); if ($bean->trans_type == 'Invoice') { if ($bean->amount_paid == 0) { $emailTemp->retrieve($this->INVOICE_ZERO_TEMPLATE); } else { $emailTemp->retrieve($this->INVOICE_TEMPLATE); } } elseif ($bean->trans_type == 'CreditMemo') { $emailTemp->retrieve($this->CREDIT_MEMO_TEMPLATE); } $emailObj = new Email(); $defaults = $emailObj->getSystemDefaultEmail(); //SET TO ADDRESSES $toAddresses = array(); $toAddresses[$clientObj->first_name . ' ' . $clientObj->last_name] = $clientObj->email1; if ($bean->email_address != '') { $extraEmails = explode(',', $bean->email_address); foreach ($extraEmails as $email) { $toAddresses[$email] = $email; } } //REPLACE VALUES FOR KEYS IN EMAIL TEMPLATE $data = array($clientObj->first_name . ' ' . $clientObj->last_name, $clientObj->first_name, $bean->amount_total, $itemObj->display_name, $sale_person['sales_full_name'], $sale_person['sales_first_name']); $keys = array('$contact_name', '$contact_first_name', '$amount', '$product', '$sales_full_name', '$sales_first_name'); $body = str_replace($keys, $data, $emailTemp->body_html); $subject = str_replace($keys, $data, $emailTemp->subject); //ATTACH INVOICE PDF $attachedFiles = array(array('file_location' => "cache/invoices/", 'filename' => $bean->name . ".pdf")); //SEND EMAIL $this->_Send_Email($this->BILLING_EMAIL, $defaults['name'], $toAddresses, $subject . ' - ' . $bean->name, 'Contacts', $clientObj->id, $body, $attachedFiles, true); } }
function getPreferredEmail() { $ret = array(); $prefName = $this->getPreference('mail_fromname'); $prefAddr = $this->getPreference('mail_fromaddress'); if (isset($prefAddr) && !empty($prefAddr)) { $ret['name'] = $prefName; $ret['email'] = $prefAddr; } elseif (isset($this->email1) && !empty($this->email1)) { $ret['name'] = trim($this->first_name . ' ' . $this->last_name); $ret['email'] = $this->email1; } elseif (isset($this->email2) && !empty($this->email2)) { $ret['name'] = trim($this->first_name . ' ' . $this->last_name); $ret['email'] = $this->email2; } else { require_once 'modules/Emails/Email.php'; $email = new Email(); $ret = $email->getSystemDefaultEmail(); } return $ret; }
public function run($data) { global $timedate; $bean = BeanFactory::getBean('AOR_Scheduled_Reports', $data); $report = $bean->get_linked_beans('aor_report', 'AOR_Reports'); if ($report) { $report = $report[0]; } else { return false; } $html = "<h1>{$report->name}</h1>" . $report->build_group_report(); $html .= <<<EOF <style> h1{ color: black; } .list { font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;font-size: 12px; background: #fff;margin: 45px;width: 480px;border-collapse: collapse;text-align: left; } .list th { font-size: 14px; font-weight: normal; color: black; padding: 10px 8px; border-bottom: 2px solid black}; } .list td { padding: 9px 8px 0px 8px; } </style> EOF; $emailObj = new Email(); $defaults = $emailObj->getSystemDefaultEmail(); $mail = new SugarPHPMailer(); $mail->setMailerForSystem(); $mail->IsHTML(true); $mail->From = $defaults['email']; $mail->FromName = $defaults['name']; $mail->Subject = from_html($bean->name); $mail->Body = $html; $mail->prepForOutbound(); $success = true; $emails = $bean->get_email_recipients(); foreach ($emails as $email_address) { $mail->ClearAddresses(); $mail->AddAddress($email_address); $success = $mail->Send() && $success; } $bean->last_run = $timedate->getNow()->asDb(false); $bean->save(); return true; }
function sendInvoice($api, $args) { $global = new Global_Functions(); //$GLOBALS['log']->error("PT_Dispatch: Args: ".print_r($args,true)); if (isset($args['invoice']) && !empty($args['invoice'])) { $InvObj = BeanFactory::getBean('TRANN_Trans', $args['invoice']); if ($InvObj->trans_type == 'Invoice') { require_once "custom/CustomHandlers/Invoice_PDF.php"; } elseif ($InvObj->trans_type == 'CreditMemo') { require_once "custom/CustomHandlers/CreditMemo_PDF.php"; } $InvObj->load_relationship('contacts_trann_trans_1'); $clientObj = current($InvObj->contacts_trann_trans_1->getBeans()); // if(!empty($clients)) $clientObj = current($clients); } else { return false; } /* $clientId = $global->_get_related_id($this->bean,'contacts_trann_trans_1contacts_ida','contacts_trann_trans_1'); $clientObj = BeanFactory::getBean('Contacts'); $clientObj->retrieve($clientId);*/ if ($InvObj->trans_type == 'Invoice') { $PDFObj = new Invoice(); } elseif ($InvObj->trans_type == 'CreditMemo') { $PDFObj = new CreditMemo(); } //GET INVOICE PRODUCT ITEMS AND PRICE $items = array(); for ($k = 1; $k < 5; $k++) { $itemID = 'trann_items_id' . $k . '_c'; $price = 'amount_' . $k; if ($InvObj->{$itemID} != '' && $InvObj->{$price} != 0) { $itemObj = BeanFactory::getBean('TRANN_Items', $InvObj->{$itemID}); $taxObj = BeanFactory::getBean('TAXRA_Tax', $itemObj->taxra_tax_id_c); $items[$k]['name'] = $itemObj->display_name; $items[$k]['price'] = number_format($InvObj->{$price}, 2); $amount_net = round((double) $InvObj->{$price} / (1 + (double) $taxObj->rate / 100), 2); $amount_tax = round((double) $InvObj->{$price} - (double) $amount_net, 2); $items[$k]['amount_net'] = number_format($amount_net, 2); $items[$k]['amount_tax'] = number_format($amount_tax, 2); } } //GET PAYMENTS FOR THIS INVOICE $query = "SELECT m.name as method,pay.* FROM trann_trans_trann_payments_1_c as link, trann_payments as pay,trann_payment_method as m WHERE link.trann_trans_trann_payments_1trann_trans_ida = '" . $InvObj->id . "' AND link.deleted=0 AND pay.id=link.trann_trans_trann_payments_1trann_payments_idb AND pay.deleted=0 AND m.id=pay.trann_payment_method_id_c AND m.deleted=0 ORDER BY pay.date_entered DESC"; $result = $InvObj->db->query($query, true); $payments = array(); $j = 0; while ($row = $InvObj->db->fetchByAssoc($result)) { $payments[$j]['number'] = $row['name']; $payments[$j]['method'] = $row['method']; $payments[$j]['date'] = $row['payment_date']; if ($row['trann_trans_id1_c'] == $InvObj->id) { $payments[$j]['amount'] = number_format($row['amount_applied_1'], 2); } if ($row['trann_trans_id2_c'] == $InvObj->id) { $payments[$j]['amount'] = number_format($row['amount_applied_2'], 2); } if ($row['trann_trans_id3_c'] == $InvObj->id) { $payments[$j]['amount'] = number_format($row['amount_applied_3'], 2); } $j++; } $InvObj->amount_remaining = number_format($InvObj->amount_remaining, 2); $InvObj->amount_total = number_format($InvObj->amount_total, 2); //CREATE INVOICE $PDFObj->Generate_PDF($InvObj, $clientObj, $payments, $items); //GET EMAIL TEMPALTE FOR INVOICE $emailTemp = BeanFactory::getBean('EmailTemplates'); if ($InvObj->trans_type == 'Invoice') { $emailTemp->retrieve($global->INVOICE_TEMPLATE); } elseif ($InvObj->trans_type == 'CreditMemo') { $emailTemp->retrieve($global->CREDIT_MEMO_TEMPLATE); } $emailObj = new Email(); $defaults = $emailObj->getSystemDefaultEmail(); //SET TO ADDRESSES $toAddresses = array(); $toAddresses[$clientObj->first_name . ' ' . $clientObj->last_name] = $clientObj->email1; if ($InvObj->email_address != '') { $extraEmails = explode(',', $InvObj->email_address); foreach ($extraEmails as $email) { $toAddresses[$email] = $email; } } //REPLACE VALUES FOR KEYS IN EMAIL TEMPLATE $data = array($clientObj->first_name . ' ' . $clientObj->last_name, $clientObj->first_name, $items[1]['name']); $keys = array('$contact_name', '$contact_first_name', '$product'); $body = str_replace($keys, $data, $emailTemp->body_html); $subject = str_replace($keys, $data, $emailTemp->subject); //ATTACH INVOICE PDF $attachedFiles = array(array('file_location' => "cache/invoices/", 'filename' => $InvObj->name . ".pdf")); //SEND EMAIL if (!$global->_Send_Email($defaults['email'], $defaults['name'], $toAddresses, $subject . ' - ' . $InvObj->name, 'Contacts', $clientObj->id, $body, $attachedFiles, true)) { return false; } else { return true; } }
function sendEmail($emailTo, $emailSubject, $emailBody, $altemailBody, SugarBean $relatedBean = null, $attachments = array()) { require_once 'modules/Emails/Email.php'; require_once 'include/SugarPHPMailer.php'; $emailObj = new Email(); $defaults = $emailObj->getSystemDefaultEmail(); $mail = new SugarPHPMailer(); $mail->setMailerForSystem(); $mail->From = $defaults['email']; $mail->FromName = $defaults['name']; $mail->ClearAllRecipients(); $mail->ClearReplyTos(); $mail->Subject = from_html($emailSubject); $mail->Body = $emailBody; $mail->AltBody = $altemailBody; $mail->handleAttachments($attachments); $mail->prepForOutbound(); $mail->AddAddress($emailTo); //now create email if (@$mail->Send()) { $emailObj->to_addrs = $emailTo; $emailObj->type = 'archived'; $emailObj->deleted = '0'; $emailObj->name = $mail->Subject; $emailObj->description = $mail->AltBody; $emailObj->description_html = $mail->Body; $emailObj->from_addr = $mail->From; if ($relatedBean instanceof SugarBean && !empty($relatedBean->id)) { $emailObj->parent_type = $relatedBean->module_dir; $emailObj->parent_id = $relatedBean->id; } $emailObj->date_sent = TimeDate::getInstance()->nowDb(); $emailObj->modified_user_id = '1'; $emailObj->created_by = '1'; $emailObj->status = 'sent'; $emailObj->save(); return true; } return false; }
/** * 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; }
function Send_Client_Email() { if ($this->arrBeans['contacts_1']->email1 != '') { $emailTemplate = 'xxxx-deddd-ggggg-eeee'; //GET EMAIL TEMPALTE FOR INVOICE $emailTemp = BeanFactory::getBean('EmailTemplates'); $emailTemp->retrieve($emailTemplate); $emailObj = new Email(); $defaults = $emailObj->getSystemDefaultEmail(); //SET TO ADDRESS $toAddresses = array(); if (!empty($this->arrBeans['application']->app_contact_email_address_c)) { $toAddresses[$this->arrBeans['contacts_1']->first_name . " " . $this->arrBeans['contacts_1']->last_name] = $this->arrBeans['application']->app_contact_email_address_c; } else { $toAddresses[$this->arrBeans['contacts_1']->first_name . " " . $this->arrBeans['contacts_1']->last_name] = $this->arrBeans['contacts_1']->email1; } //REPLACE VALUES FOR KEYS IN EMAIL TEMPLATE $data1 = $this->GetLongName($this->arrBeans['application'], $this->arrBeans['contacts_1']); $data = array($this->arrBeans['contacts_1']->first_name, $this->arrBeans['application']->name, $this->arrBeans['application']->application_type, $data1['LongName']); $keys = array('$contact_first_name', '$acc_num', '$acc_type', '$acc_name'); $body = str_replace($keys, $data, $emailTemp->body_html); //SEND EMAIL $this->_Send_Email($defaults['email'], $defaults['name'], $toAddresses, $emailTemp->subject, 'SLCM_Applications', $this->arrBeans['application']->id, $body, array(), true); $GLOBALS['log']->info("Email to fund account has been sent. Client: " . $this->arrBeans['contacts_1']->first_name . " " . $this->arrBeans['contacts_1']->last_name); } else { $GLOBALS['log']->error("Email to fund account has not been sent: email is empty! Client: " . $this->arrBeans['contacts_1']->first_name . " " . $this->arrBeans['contacts_1']->last_name); } }