public function indexAction() { $this->_helper->viewRenderer->setNoRender(true); $this->_helper->layout()->disableLayout(); $date = new Zend_Date(); $email_model = new Default_Model_EmailLogs(); $cron_model = new Default_Model_Cronstatus(); // appraisal notifications $this->checkperformanceduedate(); // feed forward notifications // $this->checkffduedate(); $cron_status = $cron_model->getActiveCron('General'); if ($cron_status == 'yes') { try { //updating cron status table to in-progress $cron_data = array('cron_status' => 1, 'cron_type' => 'General', 'started_at' => gmdate("Y-m-d H:i:s")); $cron_id = $cron_model->SaveorUpdateCronStatusData($cron_data, ''); if ($cron_id != '') { $mail_data = $email_model->getNotSentMails(); if (count($mail_data) > 0) { foreach ($mail_data as $mdata) { $options = array(); $options['header'] = $mdata['header']; $options['message'] = $mdata['message']; $options['subject'] = $mdata['emailsubject']; $options['toEmail'] = $mdata['toEmail']; $options['toName'] = $mdata['toName']; if ($mdata['cc'] != '') { $options['cc'] = $mdata['cc']; } if ($mdata['bcc'] != '') { $options['bcc'] = $mdata['bcc']; } // to send email $mail_status = sapp_Mail::_email($options); $mail_where = array('id=?' => $mdata['id']); $new_maildata['modifieddate'] = gmdate("Y-m-d H:i:s"); if ($mail_status === true) { $new_maildata['is_sent'] = 1; //to udpate email log table that mail is sent. $id = $email_model->SaveorUpdateEmailData($new_maildata, $mail_where); } } //end of for loop } //end of mails count if //updating cron status table to completed. $cron_data = array('cron_status' => 0, 'completed_at' => gmdate("Y-m-d H:i:s")); $cron_id = $cron_model->SaveorUpdateCronStatusData($cron_data, "id = " . $cron_id); } //end of cron status id if } catch (Exception $e) { } } //end of cron status if }
/** * This function is used to send mail. * @param Array $options = data that needed to send email * @return string On success id ,on failure error message. */ public static function _sendEmail($options) { $email_model = new Default_Model_EmailLogs(); $date = new Zend_Date(); if (is_array($options['toEmail'])) { $toemailData = implode(',', $options['toEmail']); } else { $toemailData = $options['toEmail']; } $data = array('toEmail' => $toemailData, 'toName' => isset($options['toName']) ? $options['toName'] : NULL, 'emailsubject' => $options['subject'], 'header' => $options['header'], 'message' => $options['message'], 'createddate' => $date->get('yyyy-MM-dd HH:mm:ss'), 'modifieddate' => $date->get('yyyy-MM-dd HH:mm:ss')); $empArrList = ''; if (isset($options['cc'])) { $data['cc'] = $options['cc']; } if (isset($options['bcc'])) { if (!empty($options['bcc'])) { $empArrList = implode(',', $options['bcc']); } $data['bcc'] = $empArrList; //$options['bcc'] = $empArrList; } $id = $email_model->SaveorUpdateEmailData($data, ''); if (!isset($options['cron'])) { //echo "<pre>";print_r($options); $mail_status = sapp_Mail::_email($options); $where = array('id=?' => $id); $newdata['modifieddate'] = $date->get('yyyy-MM-dd HH:mm:ss'); $newdata['is_sent'] = 1; if ($mail_status === true) { $id = $email_model->SaveorUpdateEmailData($newdata, $where); return $id; } else { return "fail"; } } }
public static function _sendCalendarEmailOld1($options) { // Pear Mail Library require_once "Mail.php"; $email_model = new Default_Model_EmailLogs(); $date = new Zend_Date(); if (is_array($options['toEmail'])) { $toemailData = implode(',', $options['toEmail']); } else { $toemailData = $options['toEmail']; } $meeting_duration = 3600; // 1hours $ISTTimeDifferenceInMS = 16200; $from_address = !empty($options['fromEmail']) ? $options['fromEmail'] : SUPERADMIN_EMAIL; $from_name = !empty($options['fromName']) ? $options['fromName'] : DONOTREPLYNAME; $to_name = isset($options['toName']) ? $options['toName'] : NULL; $to_address = $toemailData; $startTime = !empty($options['starttime']) ? $options['starttime'] : "01/01/2015 13:00:00"; /* Meeting Stamp = Interview Date + Time */ $startdatetime = sprintf("%s %s", $options['interviewdate'], $options['starttime']); $meetingstamp = STRTOTIME($startdatetime . " UTC"); //$endTime = (!empty($options['endtime'])) ? $options['endtime'] : "01/01/2015 14:00:00"; //$meetingstamp = STRTOTIME($startTime . " UTC"); $dtstart = GMDATE("Ymd\\THis\\Z", $meetingstamp - $ISTTimeDifferenceInMS); $dtend = GMDATE("Ymd\\THis\\Z", $meetingstamp - ($ISTTimeDifferenceInMS + $meeting_duration)); $subject = $options['subject']; $description = str_replace("\r\n", "\\n", $options['message']); $location = !empty($options['location']) ? $options['location'] : "Delta HR Office"; $domain = 'deltaintech.com'; $cal_unique_id = isset($options['calUniqueID']) ? $options['calUniqueID'] : date("Ymd\\TGis", strtotime($startTime)) . rand() . "@" . $domain; $cal_method = isset($options['method']) ? $options['method'] : 'REQUEST'; $mime_boundary = "----Meeting Booking----" . MD5(TIME()); $headers = array("From" => $from_name . " <" . $from_address . ">", "Reply-To" => $from_name . " <" . $from_address . ">", "MIME-Version" => "1.0", "Content-Type" => "multipart/alternative; boundary=\"{$mime_boundary}\"", "Content-class" => "urn:content-classes:calendarmessage"); //Create Email Body (HTML) $message = "--{$mime_boundary}\r\n"; $message .= "Content-Type: text/html; charset=UTF-8\n"; $message .= "Content-Transfer-Encoding: 8bit\n\n"; $message .= "<html>\n"; $message .= "<body>\n"; $message .= '<p>Dear ' . $to_name . ',</p>'; $message .= '<p>' . $description . '</p>'; $message .= "</body>\n"; $message .= "</html>\n"; $message .= "--{$mime_boundary}\r\n"; $ical = 'BEGIN:VCALENDAR' . "\r\n" . 'PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN' . "\r\n" . 'VERSION:2.0' . "\r\n" . 'METHOD:' . $cal_method . "\r\n" . 'BEGIN:VTIMEZONE' . "\r\n" . 'TZID:(UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi' . "\r\n" . 'BEGIN:STANDARD' . "\r\n" . 'DTSTART:20091101T020000' . "\r\n" . 'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11' . "\r\n" . 'TZOFFSETFROM:-0400' . "\r\n" . 'TZOFFSETTO:-0500' . "\r\n" . 'TZNAME:EST' . "\r\n" . 'END:STANDARD' . "\r\n" . 'BEGIN:DAYLIGHT' . "\r\n" . 'DTSTART:20090301T020000' . "\r\n" . 'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3' . "\r\n" . 'TZOFFSETFROM:-0500' . "\r\n" . 'TZOFFSETTO:-0400' . "\r\n" . 'TZNAME:EDST' . "\r\n" . 'END:DAYLIGHT' . "\r\n" . 'END:VTIMEZONE' . "\r\n" . 'BEGIN:VEVENT' . "\r\n" . 'ORGANIZER;CN="' . $from_name . '":MAILTO:' . $from_address . "\r\n" . 'ATTENDEE;CN="' . $to_name . '";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:' . $to_address . "\r\n" . 'LAST-MODIFIED:' . date("Ymd\\TGis") . "\r\n" . 'UID:' . $cal_unique_id . "\r\n" . 'DTSTAMP:' . date("Ymd\\TGis") . "\r\n" . 'DTSTART:' . $dtstart . "\r\n" . 'DTEND:' . $dtend . "\r\n" . 'TRANSP:OPAQUE' . "\r\n" . 'SEQUENCE:1' . "\r\n" . 'SUMMARY:' . $subject . "\r\n" . 'LOCATION:' . $location . "\r\n" . 'CLASS:PUBLIC' . "\r\n" . 'PRIORITY:5' . "\r\n" . 'BEGIN:VALARM' . "\r\n" . 'TRIGGER:-PT15M' . "\r\n" . 'ACTION:DISPLAY' . "\r\n" . 'DESCRIPTION:Reminder' . "\r\n" . 'END:VALARM' . "\r\n" . 'END:VEVENT' . "\r\n" . 'END:VCALENDAR' . "\r\n"; $message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST\\n'; $message .= "Content-Transfer-Encoding: 8bit\n\n"; $message .= $ical; //$options['ical'] = (!empty($options['ical'])) ? $options['ical'] : $ical; $options['message'] = $message; $data = array('toEmail' => $toemailData, 'toName' => isset($options['toName']) ? $options['toName'] : NULL, 'emailsubject' => $options['subject'], 'header' => $options['header'], 'message' => $message, 'createddate' => $date->get('yyyy-MM-dd HH:mm:ss'), 'modifieddate' => $date->get('yyyy-MM-dd HH:mm:ss')); /* if (isset($options['cc'])) $data['cc'] = $options['cc']; if (isset($options['bcc'])) $data['bcc'] = $options['bcc']; */ $id = $email_model->SaveorUpdateEmailData($data, ''); if (!isset($options['cron'])) { //$mail_status = sapp_Mail::_emailascalendar($options); $smtp = Mail::factory('smtp', array('host' => MAIL_TLS . '://' . MAIL_SMTP, 'port' => MAIL_PORT, 'auth' => true, 'username' => MAIL_USERNAME, 'password' => MAIL_PASSWORD)); $mail_status = $smtp->send($to_address, $headers, $message); $where = array('id=?' => $id); $newdata['modifieddate'] = $date->get('yyyy-MM-dd HH:mm:ss'); $newdata['is_sent'] = 1; if ($mail_status) { $id = $email_model->SaveorUpdateEmailData($newdata, $where); return $id; } else { return "fail"; } } }