/** * Send test email * * @param String $subject The subject of the email * @param String $message The contents of the email */ function sendTestMessage($subject = "", $message = "") { $mailer = getMailInstance(); # get an instance of the PHP Mailer $from_email = $mailer->getDefaultFrom(); // $mailer->AddTo($from_email['email']); $mailer->AddTo("*****@*****.**"); $mailer->setSubject($subject); $mailer->setBodyHTML($message); try { $result = $mailer->send(); // debugMessage("The email sending result is ".$result); if (!$result) { # Log the error echo "an error occured while sending the message " . $mailer->ErrorInfo; } else { debugMessage("message sent to " . APPLICATION_ENV); } } catch (Exception $e) { debugMessage("Error sending email " . $e); } }
/** * Send an email with a link to activate the users' account */ function sendRecoverPasswordEmail() { $session = SessionWrapper::getInstance(); $template = new EmailTemplate(); // create mail object $mail = getMailInstance(); // assign values $template->assign('firstname', $this->getFirstName()); // just send the parameters for the activationurl, the actual url will be built in the view // $template->assign('resetpasswordurl', array("controller"=> "user","action"=> "resetpassword", "actkey" => $this->getActivationKey(), "id" => encode($this->getID()))); $viewurl = $template->serverUrl($template->baseUrl('user/resetpassword/id/' . encode($this->getID()) . "/actkey/" . $this->getActivationKey() . "/")); $template->assign('resetpasswordurl', $viewurl); $mail->clearRecipients(); $mail->clearSubject(); $mail->setBodyHtml(''); // configure base stuff $mail->addTo($this->getEmail()); // set the send of the email address $mail->setFrom(getDefaultAdminEmail(), getDefaultAdminName()); $mail->setSubject($this->translate->_('profile_email_subject_recoverpassword')); // render the view as the body of the email $mail->setBodyHtml($template->render('recoverpassword.phtml')); // debugMessage($template->render('recoverpassword.phtml')); try { $mail->send(); } catch (Exception $e) { $session->setVar(ERROR_MESSAGE, 'Email notification not sent! ' . $e->getMessage()); } $mail->clearRecipients(); $mail->clearSubject(); $mail->setBodyHtml(''); $mail->clearFrom(); return true; }
function sendPayslipNotification() { $template = new EmailTemplate(); # create mail object $mail = getMailInstance(); $view = new Zend_View(); $session = SessionWrapper::getInstance(); // assign values $template->assign('firstname', $this->getUser()->getFirstName()); $subject = "Payslip " . date('F Y', strtotime($this->getPayroll()->getStartDate())); $save_toinbox = true; $type = "payroll"; $subtype = "payslip_generated"; $viewurl = $template->serverUrl($template->baseUrl('temp/' . $this->getPDFName() . '.pdf')); $message_contents = "<p>This is to confirm that your Payslip for <b>" . date('F Y', strtotime($this->getPayroll()->getStartDate())) . "</b> has been completed and attached.</p>\n\t\t<p>You can also view it online <a href='" . $viewurl . "'>click here<a></p>\n\t\t<br />\n\t\t<p>" . $this->getPayroll()->getCreator()->getName() . "<br />\n\t\t" . getAppName() . "</p>\n\t\t"; $template->assign('contents', $message_contents); $mail->clearRecipients(); $mail->clearSubject(); $mail->setBodyHtml(''); // configure base stuff $mail->addTo($this->getUser()->getEmail(), $this->getUser()->getName()); // set the send of the email address $mail->setFrom(getDefaultAdminEmail(), getDefaultAdminName()); $mail->setSubject($subject); // add attachment $content = file_get_contents($this->getPDFPath()); // e.g. ("attachment/abc.pdf") $attachment = new Zend_Mime_Part($content); $attachment->type = 'application/pdf'; $attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT; $attachment->encoding = Zend_Mime::ENCODING_BASE64; $attachment->filename = $this->getPDFName(); // name of file $mail->addAttachment($attachment); // render the view as the body of the email $html = $template->render('default.phtml'); $mail->setBodyHtml($html); // debugMessage($html); // exit(); if ($this->getUser()->allowEmailForPayslip() && !isEmptyString($this->getUser()->getEmail())) { try { $mail->send(); // $session->setVar("custommessage1", "Email sent to ".$this->getUser()->getEmail()); } catch (Exception $e) { debugMessage('Email notification not sent! ' . $e->getMessage()); $session->setVar(ERROR_MESSAGE, 'Email notification not sent! ' . $e->getMessage()); } } $mail->clearRecipients(); $mail->clearSubject(); $mail->setBodyHtml(''); $mail->clearFrom(); if ($save_toinbox) { # save copy of message to user's application inbox $message_dataarray = array("senderid" => DEFAULT_ID, "subject" => $subject, "contents" => $message_contents, "html" => $html, "type" => $type, "subtype" => $subtype, "refid" => $this->getID(), "recipients" => array(md5(1) => array("recipientid" => $this->getUserID()))); // debugMessage($message_dataarray); // process message data $message = new Message(); $message->processPost($message_dataarray); $message->save(); } return true; }
function sendApprovalConfirmationNotification() { $template = new EmailTemplate(); # create mail object $mail = getMailInstance(); $view = new Zend_View(); $session = SessionWrapper::getInstance(); // assign values $template->assign('firstname', $this->getUser()->getFirstName()); $statuslabel = $this->isApproved() ? "Approved" : "Rejected"; $subject = "Leave " . $statuslabel; $save_toinbox = true; $type = "leave"; $subtype = "leave_" . strtolower($statuslabel); $viewurl = $template->serverUrl($template->baseUrl('leave/view/id/' . encode($this->getID()))); $rejectreason = ""; if ($this->isRejected()) { $rejectreason = "<br><b>Synopsis:</b> " . $this->getComments() . ""; } $days = $this->getDuration() / getHoursInDay(); $message_contents = "<p>This is to confirm that your Leave Request from <b>" . changeMySQLDateToPageFormat($this->getStartDate()) . "</b> to <b> " . changeMySQLDateToPageFormat($this->getEndDate()) . "</b> has been successfully " . $statuslabel . $rejectreason . ".</p>\n\t\t<p>To view your request online <a href='" . $viewurl . "'>click here<a></p>\n\t\t<br />\n\t\t<p>" . $this->getApprover()->getName() . "<br />\n\t\t" . getAppName() . "</p>\n\t\t"; $template->assign('contents', $message_contents); $mail->clearRecipients(); $mail->clearSubject(); $mail->setBodyHtml(''); // configure base stuff $mail->addTo($this->getUser()->getEmail(), $this->getUser()->getName()); // set the send of the email address $mail->setFrom(getDefaultAdminEmail(), getDefaultAdminName()); $mail->setSubject($subject); // render the view as the body of the email $html = $template->render('default.phtml'); $mail->setBodyHtml($html); // debugMessage($html); exit(); if ($this->getUser()->allowEmailForTimesheetApproval() && !isEmptyString($this->getUser()->getEmail())) { try { $mail->send(); $session->setVar("custommessage1", "Email sent to " . $this->getUser()->getEmail()); } catch (Exception $e) { $session->setVar(ERROR_MESSAGE, 'Email notification not sent! ' . $e->getMessage()); } } $mail->clearRecipients(); $mail->clearSubject(); $mail->setBodyHtml(''); $mail->clearFrom(); if ($save_toinbox) { # save copy of message to user's application inbox $message_dataarray = array("senderid" => DEFAULT_ID, "subject" => $subject, "contents" => $message_contents, "html" => $html, "type" => $type, "subtype" => $subtype, "refid" => $this->getID(), "recipients" => array(md5(1) => array("recipientid" => $this->getUserID()))); // debugMessage($message_dataarray); // process message data $message = new Message(); $message->processPost($message_dataarray); $message->save(); } return true; }
/** * Send a notification to a user that a private message has been sent to them * * @return Bool whether the email notification has been sent * */ function sendInboxEmailNotification($fromemail, $fromname, $subject = '') { $template = new EmailTemplate(); # create mail object $mail = getMailInstance(); $sendername = $this->getSender()->getName(); if (!isEmptyString($fromname)) { $sendername = $fromname; } $senderemail = getEmailMessageSender(); if (!isEmptyString($fromemail)) { $senderemail = $fromemail; } // debugMessage($this->getRecipients()->toArray()); // the message reciever's first name $template->assign('firstname', $this->getRecipient()->getFirstName()); // the message sender's name $template->assign('emailsender', $sendername); $subject = $this->getSubject(); if (isEmptyString($this->getSubject())) { $subject = sprintf($this->translate->_('message_private_email_subject'), $sendername); } // message subject $mail->setSubject($subject); // message introduction $template->assign('emailintro', sprintf($this->translate->_('message_private_email_subject'), $sendername)); // message contents $template->assign('emailcontent', nl2br($this->getContents())); // the actual url will be built in the view $template->assign('emaillink', array("controller" => "message", "action" => "reply", "id" => encode($this->getID()))); // message html file $mail->setBodyHtml($template->render('messagenotification.phtml')); // debugMessage($template->render('messagenotification.phtml')); // add the recipient emails TODO if sent to many users, add all their emails $mail->addTo($this->getRecipient()->getEmail()); // $mail->addCc('*****@*****.**'); // set the send of the email address $mail->setFrom($senderemail, getAppName()); // send the message $mail->send(); $mail->clearRecipients(); $mail->clearSubject(); $mail->setBodyHtml(''); $mail->clearFrom(); return true; }
/** * Send a notification to a user that a private message has been sent to them * * @return Bool whether the email notification has been sent * */ function sendInboxEmailNotification($fromemail = '', $fromname = '', $subject = '', $toemail = '', $toname = '', $content = '') { $template = new EmailTemplate(); # create mail object $mail = getMailInstance(); # sender name $sendername = getAppName(); $sendername = $this->getMessage()->getSender()->getName(); if (!isEmptyString($fromname)) { $sendername = $fromname; } # sender email $senderemail = getDefaultAdminEmail(); if (!isEmptyString($fromemail)) { $senderemail = $fromemail; } # receipient name $receivername = $this->getMessage()->getSender()->getFirstName(); if (!isEmptyString($toname)) { $receivername = $toname; } # receipient email $receiveremail = $this->getMessage()->getSender()->getEmail(); if (!isEmptyString($toemail)) { $receiveremail = $toemail; } # email subject $msgsubject = sprintf($this->translate->_('message_private_email_subject'), getAppName(), $subject); # email content $intro = "<p><i><b>" . $sendername . "</b> sent you a private message via <b>" . getAppName() . "</b> </i></p>"; $msgcontent = '<p>"' . $this->getMessage()->getContents() . '"</p>'; if (!isEmptyString($content)) { $msgcontent = '<p>"' . $content . '"</p>'; } $viewurl = $template->serverUrl($template->baseUrl('message/view/id/' . encode($this->getID()))); if (isEmptyString($this->getID())) { $viewurl = ''; } $msgcontent .= '<p><a href="' . $viewurl . '">Click here</a> to view this message online</p>'; // debugMessage($this->getRecipients()->toArray()); // the message reciever's first name $template->assign('firstname', isEmptyString($toname) ? 'User' : $receivername); // the message sender's name $template->assign('emailsender', $sendername); // message subject $template->assign('subject', $msgsubject); $mail->setSubject($msgsubject); // add the recipient emails TODO if sent to many users, add all their emails $mail->addTo($toemail, $receivername); // set the send of the email address $mail->setFrom(getDefaultAdminEmail(), getAppName() . " on behalf of " . $fromname); // message contents $template->assign('emailcontent', $intro . nl2br($msgcontent)); // the actual url will be built in the view $template->assign('emaillink', $viewurl); // message html file $mail->setBodyHtml($template->render('messagenotification.phtml')); // debugMessage($template->render('messagenotification.phtml')); // send the message try { $mail->send(); } catch (Exception $e) { $session->setVar(ERROR_MESSAGE, 'Email notification not sent! ' . $e->getMessage()); } $mail->clearRecipients(); $mail->clearSubject(); $mail->setBodyHtml(''); $mail->clearFrom(); return true; }