protected function _sendEmail($to, $subject, $message) { if (YOUNIQUE_TESTSERVER) { $subject = "TEST ONLY: " . $subject; $to = array('*****@*****.**', '*****@*****.**'); } App::uses('YouniqueEmail', 'Lib'); // YouniqueEmail::send(array('message' => $message), 'facebooklist', $to, $subject); YouniqueEmail::sendEmail(['message' => $message], 'facebooklist', $to, $subject); }
/** * Sends an email to the queue to make sure email sends don't hold up http requests on the site. * @param $emailData * @param $templateName * @param $to * @param $subjectBlockName * @param $tag * @param $locale * @param null $emailOptions * @return bool|\Guzzle\Service\Resource\Model|string * @throws Exception */ public static function queueEmail($emailData, $templateName, $to, $subjectBlockName, $tag, $locale, $emailOptions = null) { $to = trim($to); if (Sqs::useQueue()) { $data = ['to' => $to, 'locale' => $locale, 'template' => $templateName, 'tag' => $tag, 'subject' => $subjectBlockName, 'email_data' => $emailData, 'email_options' => $emailOptions]; if (!defined('EMAIL_QUEUE_DB') || !defined('EMAIL_QUEUE_SQS')) { CakeLog::error("Email Queue Table name or SQS Url not found."); return false; } $ddb = new Ddb(EMAIL_QUEUE_DB); $sqs = new Sqs(EMAIL_QUEUE_SQS); // save to DDB $details_id = $ddb->guid(); $result = $ddb->saveData($details_id, $data); // send to SQS $sqs->send($details_id); return $result; } else { $result = YouniqueEmail::sendEmail($emailData, $templateName, $to, $subjectBlockName, $tag, $locale, false, $emailOptions); return $result; } }
public function preview() { // This operation is only allowed on test servers. if (!YOUNIQUE_TEST_SERVER) { throw new NotFoundException(); } $this->viewClass = ''; $this->view = "html"; $this->RequestHandler->respondAs('html'); $this->response->type('html'); if ($this->request->is('post')) { $emailData = isset($this->request->data['emailData']) ? $this->request->data['emailData'] : null; $templateName = isset($this->request->data['templateName']) ? $this->request->data['templateName'] : ''; $subjectBlockName = isset($this->request->data['subjectBlockName']) ? $this->request->data['subjectBlockName'] : ''; $tag = isset($this->request->data['tag']) ? $this->request->data['tag'] : ''; $locale = isset($this->request->data['locale']) ? $this->request->data['locale'] : 'en-US'; // if (empty($templateName) || empty($subjectBlockName) || empty($tag) || empty($emailData)) { // throw new NotFoundException; // } // Explode emailData into associative array. $newData = explode(PHP_EOL, $emailData); $emailData = array(); foreach ($newData as $data) { $data = explode(', ', $data); $emailData[$data[0]] = $data[1]; } $response = YouniqueEmail::sendEmail($emailData, $templateName, '*****@*****.**', $subjectBlockName, $tag, $locale, true); $this->set('response', $response); return $this->render('/Admin/emailpreview'); } else { return $this->render('/Admin/emailpreview'); } }
/** * Send email * * @param $data * @param $to * @param $locale * @param $template * @param $tag * @param $subject * @param $emailOptions * @throws Exception */ private function sendEmail($data, $to, $locale, $template, $tag, $subject, $emailOptions) { YouniqueEmail::sendEmail($data, $template, $to, $subject, $tag, $locale, false, $emailOptions); }