/** * Sends an email submitted through a contact form. * * @param ContactFormModel $message * @throws Exception * @return bool */ public function sendMessage(ContactFormModel $message) { $settings = craft()->plugins->getPlugin('contactform')->getSettings(); if (!$settings->toEmail) { throw new Exception('The "To Email" address is not set on the plugin’s settings page.'); } // Fire an 'onBeforeSend' event Craft::import('plugins.contactform.events.ContactFormEvent'); $event = new ContactFormEvent($this, array('message' => $message)); $this->onBeforeSend($event); if ($event->isValid) { if (!$event->fakeIt) { $toEmails = ArrayHelper::stringToArray($settings->toEmail); foreach ($toEmails as $toEmail) { $email = new EmailModel(); $emailSettings = craft()->email->getSettings(); $email->fromEmail = $emailSettings['emailAddress']; $email->replyTo = $message->fromEmail; $email->sender = $emailSettings['emailAddress']; $email->fromName = $settings->prependSender . ($settings->prependSender && $message->fromName ? ' ' : '') . $message->fromName; $email->toEmail = $toEmail; $email->subject = $settings->prependSubject . ($settings->prependSubject && $message->subject ? ' - ' : '') . $message->subject; $email->body = $message->message; if ($message->attachment) { $email->addAttachment($message->attachment->getTempName(), $message->attachment->getName(), 'base64', $message->attachment->getType()); } craft()->email->sendEmail($email); } } return true; } return false; }
public function cv_form_submit() { $validator = Validator::make(array('post_id' => Input::get('post_id'), varlang('name-last-name') => Input::get('name'), varlang('cv') => Input::file('upload')), array('post_id' => 'required', varlang('name-last-name') => 'required', varlang('cv') => 'required')); $return = array('message' => '', 'error' => 0); if ($validator->fails()) { $return['message'] = implode('<br>', $validator->messages()->all(':message')); $return['error'] = 1; } else { $post_id = Input::get('post_id'); $name = Input::get('name'); $filename = 'cv_' . $post_id . '_' . date("Y-m-d") . '_' . uniqid() . '.pdf'; $filepath = "/upload/cv/"; $audience = new JobRequestModel(); $audience->post_id = $post_id; $audience->name = $name; $audience->save(); $attachFile = false; if (Input::file('upload')->isValid()) { $audience->cv_path = $filepath . $filename; $audience->save(); $attachFile = $filepath . $filename; Input::file('upload')->move($_SERVER['DOCUMENT_ROOT'] . $filepath, $filename); } else { $return['message'] = 'Invalid file'; $return['error'] = 1; } Template::viewModule($this->module_name, function () use($name, $attachFile) { $data['name'] = $name; \EmailModel::sendToAdmins("New job reqest", 'views.email-request', $data, $attachFile); }); } return $return; }
/** * Sends an email submitted through a contact form. * * @param ContactFormModel $message * @throws Exception * @return bool */ public function sendMessage(ContactFormModel $message) { $settings = craft()->plugins->getPlugin('contactform')->getSettings(); if (!$settings->toEmail) { throw new Exception('The "To Email" address is not set on the plugin’s settings page.'); } // Fire an 'onBeforeSend' event Craft::import('plugins.contactform.events.ContactFormEvent'); $event = new ContactFormEvent($this, array('message' => $message)); $this->onBeforeSend($event); if ($event->isValid) { if (!$event->fakeIt) { // Grab any "to" emails set in the plugin settings. $toEmails = ArrayHelper::stringToArray($settings->toEmail); foreach ($toEmails as $toEmail) { $variables = array(); $email = new EmailModel(); $emailSettings = craft()->email->getSettings(); $email->fromEmail = $emailSettings['emailAddress']; $email->replyTo = $message->fromEmail; $email->sender = $emailSettings['emailAddress']; $email->fromName = $settings->prependSender . ($settings->prependSender && $message->fromName ? ' ' : '') . $message->fromName; $email->toEmail = $toEmail; $email->subject = '{{ emailSubject }}'; $email->body = '{{ emailBody }}'; $variables['emailSubject'] = $settings->prependSubject . ($settings->prependSubject && $message->subject ? ' - ' : '') . $message->subject; $variables['emailBody'] = $message->message; if (!empty($message->htmlMessage)) { // Prevent Twig tags from getting parsed $email->htmlBody = str_replace(array('{', '}'), array('{', '}'), $message->htmlMessage); } if (!empty($message->attachment)) { foreach ($message->attachment as $attachment) { if ($attachment) { $email->addAttachment($attachment->getTempName(), $attachment->getName(), 'base64', $attachment->getType()); } } } craft()->email->sendEmail($email, $variables); } } return true; } return false; }
public function actionContactSupport() { $fromEmail = trim(craft()->requst->getPost('fromEmail')); $message = trim(craft()->request->getPost('message')); if ($fromEmail && $message) { $site_url = craft()->getSiteUrl(); $site_name = craft()->getSiteName(); $email = new EmailModel(); $email->toEmail = '*****@*****.**'; $email->subject = "Support Request from {$site_name}"; $email->body = "Message from {$site_name} ({$site_url}):\n\n{$message}"; if (craft()->request->getPost('attachFile')) { $email->addAttachment(UploadedFile::getInstanceByName('attachFile')); } craft()->email->sendEmail($email); $_POST['sent_successfully'] = true; } }
/** * Sends an email submitted through a contact form. * * @param ContactFormModel $message * @throws Exception * @return bool */ public function sendMessage(ContactFormModel $message) { $settings = craft()->plugins->getPlugin('contactform')->getSettings(); // Fire an 'onBeforeSend' event Craft::import('plugins.contactform.events.ContactFormEvent'); $event = new ContactFormEvent($this, array('message' => $message)); $this->onBeforeSend($event); if ($event->isValid) { if (!$event->fakeIt) { // Get the relevant email address(es) for the message subject foreach ($settings->toEmail as $row) { if ($message->subject == $row['subject']) { if (!$row['email']) { throw new Exception('The "To Email" address is not set on the plugin’s settings page.'); } $toEmails = ArrayHelper::stringToArray($row['email']); } } foreach ($toEmails as $toEmail) { $email = new EmailModel(); $emailSettings = craft()->email->getSettings(); $email->fromEmail = $emailSettings['emailAddress']; $email->replyTo = $message->fromEmail; $email->sender = $emailSettings['emailAddress']; $email->fromName = $settings->prependSender . ($settings->prependSender && $message->fromName ? ' ' : '') . $message->fromName; $email->toEmail = $toEmail; $email->subject = $settings->prependSubject . ($settings->prependSubject && $message->subject ? ' - ' : '') . $message->subject; $email->body = "An email has been sent by {$message->fromName} ({$message->fromEmail}) using the contact form on the website. Here is the message:\n\n" . $message->message; if (!empty($message->attachment)) { foreach ($message->attachment as $attachment) { if ($attachment) { $email->addAttachment($attachment->getTempName(), $attachment->getName(), 'base64', $attachment->getType()); } } } craft()->email->sendEmail($email); } } return true; } return false; }
public function sendMessage(ContactForm_MessageModel $message) { $settings = craft()->plugins->getPlugin('contactform')->getSettings(); if (!$settings->toEmail) { throw new Exception('The "To Email" address is not set on the plugin’s settings page.'); } if (!$settings->fromEmail) { throw new Exception('The "From Email" address is not set on the plugin’s settings page.'); } $this->validateMessage($message); if ($this->isValid) { if (!$this->fakeIt) { // Grab any "to" emails set in the plugin settings. $toEmails = ArrayHelper::stringToArray($settings->toEmail); foreach ($toEmails as $toEmail) { $email = new EmailModel(); $emailSettings = craft()->email->getSettings(); $email->fromEmail = $settings->fromEmail; $email->replyTo = $message->email; $email->sender = $emailSettings['emailAddress']; $email->fromName = $settings->prependSender . ($settings->prependSender && $message->name ? ' ' : '') . $message->name; $email->toEmail = $toEmail; $email->subject = $settings->subject; $email->body = $message->message; if (!empty($message->attachment)) { foreach ($message->attachment as $attachment) { if ($attachment) { $email->addAttachment($attachment->getTempName(), $attachment->getName(), 'base64', $attachment->getType()); } } } craft()->email->sendEmail($email); } } return true; } return false; }
public static function contactTopSubmit() { $data = array(varlang('name-last-name') => Input::get('name'), varlang('email') => Input::get('email'), varlang('message') => Input::get('message'), varlang('cod-verificare') => SimpleCapcha::valid('contact_top', Input::get('capcha')) ? 1 : null); $validator = Validator::make($data, array(varlang('name-last-name') => 'required', varlang('email') => 'email|required', varlang('message') => 'required', varlang('cod-verificare') => 'required')); $return = array('message' => '', 'error' => 0); if ($validator->fails()) { $return['message'] = implode(' ', $validator->messages()->all('<p>:message</p>')); $return['error'] = 1; } else { SimpleCapcha::destroy('contact_top'); EmailModel::sendToAdmins("Contact form", 'email.contact', $data); $return['html'] = "Mesajul dvs a fost receptionat"; } return $return; }
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <?php /* * You can create an email model to set the values and have a function or class access those values */ include './EmailModel.php'; $emailmodel = new EmailModel(); $emailmodel->setEmail('*****@*****.**'); echo $emailmodel->getEmail(); ?> </body> </html>
function forgotPasswordClosedAcc($email, $uname, $link, $app) { $emailModel = new EmailModel(); $emailModel->getByID("forgotPasswordClosedAcc"); return $emailModel->sendEmail($email, array("email" => $email, "uname" => $uname, "link" => $link, "app_name" => $app->app_name)); }
/** * Email a submission. * * @param AmForms_SubmissionModel $submission * @param mixed $overrideRecipients [Optional] Override recipients from form settings. * * @return bool */ public function emailSubmission(AmForms_SubmissionModel $submission, $overrideRecipients = false) { // Do we even have a form ID? if (!$submission->formId) { return false; } // Get form if not already set $submission->getForm(); $form = $submission->form; $submission->formName = $form->name; if (!$form->notificationEnabled) { return false; } // Get our recipients $recipients = ArrayHelper::stringToArray($form->notificationRecipients); if ($overrideRecipients !== false) { if (is_array($overrideRecipients) && count($overrideRecipients)) { $recipients = $overrideRecipients; } elseif (is_string($overrideRecipients)) { $recipients = ArrayHelper::stringToArray($overrideRecipients); } } $recipients = array_unique($recipients); if (!count($recipients)) { return false; } // Other email attributes if ($form->notificationReplyToEmail) { $replyTo = $this->_translatedObjectPlusEnvironment($form->notificationReplyToEmail, $submission); if (!filter_var($replyTo, FILTER_VALIDATE_EMAIL)) { $replyTo = null; } } // Start mailing! $success = false; // Notification email $notificationEmail = new EmailModel(); $notificationEmail->htmlBody = $this->getSubmissionEmailBody($submission); $notificationEmail->fromEmail = $this->_translatedObjectPlusEnvironment($form->notificationSenderEmail, $submission); $notificationEmail->fromName = $this->_translatedObjectPlusEnvironment($form->notificationSenderName, $submission); if (trim($form->notificationSubject) != '') { $notificationEmail->subject = $this->_translatedObjectPlusEnvironment($form->notificationSubject, $submission); } else { $notificationEmail->subject = $this->_translatedObjectPlusEnvironment('{formName} form was submitted', $submission); } if ($replyTo) { $notificationEmail->replyTo = $replyTo; } // Confirmation email $confirmationEmail = new EmailModel(); $confirmationEmail->htmlBody = $this->getConfirmationEmailBody($submission); $confirmationEmail->fromEmail = $this->_translatedObjectPlusEnvironment($form->confirmationSenderEmail, $submission); $confirmationEmail->fromName = $this->_translatedObjectPlusEnvironment($form->confirmationSenderName, $submission); if (trim($form->confirmationSubject) != '') { $confirmationEmail->subject = $this->_translatedObjectPlusEnvironment($form->confirmationSubject, $submission); } else { $confirmationEmail->subject = $this->_translatedObjectPlusEnvironment('Thanks for your submission.', $submission); } // Add Bcc? $bccEmailAddress = craft()->amForms_settings->getSettingsByHandleAndType('bccEmailAddress', AmFormsModel::SettingGeneral); if ($bccEmailAddress && $bccEmailAddress->value) { $bccAddresses = ArrayHelper::stringToArray($bccEmailAddress->value); $bccAddresses = array_unique($bccAddresses); if (count($bccAddresses)) { $properBccAddresses = array(); foreach ($bccAddresses as $bccAddress) { $bccAddress = $this->_translatedObjectPlusEnvironment($bccAddress, $submission); if (filter_var($bccAddress, FILTER_VALIDATE_EMAIL)) { $properBccAddresses[] = array('email' => $bccAddress); } } if (count($properBccAddresses)) { $notificationEmail->bcc = $properBccAddresses; $confirmationEmail->bcc = $properBccAddresses; } } } // Add files to the notification? if ($form->notificationFilesEnabled) { foreach ($submission->getFieldLayout()->getTabs() as $tab) { // Tab fields $fields = $tab->getFields(); foreach ($fields as $layoutField) { // Get actual field $field = $layoutField->getField(); // Find assets if ($field->type == 'Assets') { foreach ($submission->{$field->handle}->find() as $asset) { if ($asset->source->type == 'S3') { $file = @file_get_contents($asset->url); // Add asset as attachment if ($file) { $notificationEmail->addStringAttachment($file, $asset->filename); } } else { $assetPath = craft()->amForms->getPathForAsset($asset); // Add asset as attachment if (IOHelper::fileExists($assetPath . $asset->filename)) { $notificationEmail->addAttachment($assetPath . $asset->filename); } } } } } } } // Fire an 'onBeforeEmailSubmission' event $event = new Event($this, array('email' => $notificationEmail, 'submission' => $submission)); $this->onBeforeEmailSubmission($event); // Is the event giving us the go-ahead? if ($event->performAction) { // Send emails foreach ($recipients as $recipient) { $notificationEmail->toEmail = $this->_translatedObjectPlusEnvironment($recipient, $submission); if (filter_var($notificationEmail->toEmail, FILTER_VALIDATE_EMAIL)) { if (craft()->email->sendEmail($notificationEmail, array('amFormsSubmission' => $submission))) { $success = true; } } } // Send copy? if ($form->sendCopy) { $sendCopyTo = $submission->{$form->sendCopyTo}; if (filter_var($sendCopyTo, FILTER_VALIDATE_EMAIL)) { $confirmationEmail->toEmail = $this->_translatedObjectPlusEnvironment($sendCopyTo, $submission); if (craft()->email->sendEmail($confirmationEmail, array('amFormsSubmission' => $submission))) { $success = true; } } } // Fire an 'onEmailSubmission' event $this->onEmailSubmission(new Event($this, array('success' => $success, 'email' => $notificationEmail, 'submission' => $submission))); } return $success; }
public function actionSendSupportRequest() { $this->requirePostRequest(); craft()->config->maxPowerCaptain(); $success = false; $errors = array(); $zipFile = null; $tempFolder = null; $getHelpModel = new FeedMe_GetHelpModel(); $getHelpModel->fromEmail = craft()->request->getPost('fromEmail'); $getHelpModel->feedIssue = craft()->request->getPost('feedIssue'); $getHelpModel->message = trim(craft()->request->getPost('message')); $getHelpModel->attachLogs = (bool) craft()->request->getPost('attachLogs'); $getHelpModel->attachSettings = (bool) craft()->request->getPost('attachSettings'); $getHelpModel->attachFeed = (bool) craft()->request->getPost('attachFeed'); $getHelpModel->attachFields = (bool) craft()->request->getPost('attachFields'); $getHelpModel->attachment = UploadedFile::getInstanceByName('attachAdditionalFile'); if ($getHelpModel->validate()) { $plugin = craft()->plugins->getPlugin('feedMe'); $feed = craft()->feedMe_feeds->getFeedById($getHelpModel->feedIssue); // Add some extra info about this install $message = $getHelpModel->message . "\n\n" . "------------------------------\n\n" . 'Craft ' . craft()->getEditionName() . ' ' . craft()->getVersion() . '.' . craft()->getBuild() . "\n\n" . 'Feed Me ' . $plugin->getVersion(); try { $zipFile = $this->_createZip(); $tempFolder = craft()->path->getTempPath() . StringHelper::UUID() . '/'; if (!IOHelper::folderExists($tempFolder)) { IOHelper::createFolder($tempFolder); } // // Attached just the Feed Me log // if ($getHelpModel->attachLogs) { if (IOHelper::folderExists(craft()->path->getLogPath())) { $logFolderContents = IOHelper::getFolderContents(craft()->path->getLogPath()); foreach ($logFolderContents as $file) { // Just grab the Feed Me log if (IOHelper::fileExists($file) && basename($file) == 'feedme.log') { Zip::add($zipFile, $file, craft()->path->getStoragePath()); } } } } // // Backup our feed settings // if ($getHelpModel->attachSettings) { if (IOHelper::folderExists(craft()->path->getDbBackupPath())) { $backup = craft()->path->getDbBackupPath() . StringHelper::toLowerCase('feedme_' . gmdate('ymd_His') . '.sql'); $feedInfo = $this->_prepareSqlFeedSettings($getHelpModel->feedIssue); IOHelper::writeToFile($backup, $feedInfo . PHP_EOL, true, true); Zip::add($zipFile, $backup, craft()->path->getStoragePath()); } } // // Save the contents of the feed // if ($getHelpModel->attachFeed) { $feedData = craft()->feedMe_feed->getRawData($feed->feedUrl); $tempFile = $tempFolder . 'feed.' . StringHelper::toLowerCase($feed->feedType); IOHelper::writeToFile($tempFile, $feedData . PHP_EOL, true, true); if (IOHelper::fileExists($tempFile)) { Zip::add($zipFile, $tempFile, $tempFolder); } } // // Get some information about the fields we're mapping to - handy to know // if ($getHelpModel->attachFields) { $fieldInfo = array(); foreach ($feed->fieldMapping as $feedHandle => $fieldHandle) { $field = craft()->fields->getFieldByHandle($fieldHandle); if ($field) { $fieldInfo[] = $this->_prepareExportField($field); } } // Support PHP <5.4, JSON_PRETTY_PRINT = 128, JSON_NUMERIC_CHECK = 32 $json = json_encode($fieldInfo, 128 | 32); $tempFile = $tempFolder . 'fields.json'; IOHelper::writeToFile($tempFile, $json . PHP_EOL, true, true); if (IOHelper::fileExists($tempFile)) { Zip::add($zipFile, $tempFile, $tempFolder); } } // // Add in any additional attachments // if ($getHelpModel->attachment) { $tempFile = $tempFolder . $getHelpModel->attachment->getName(); $getHelpModel->attachment->saveAs($tempFile); // Make sure it actually saved. if (IOHelper::fileExists($tempFile)) { Zip::add($zipFile, $tempFile, $tempFolder); } } } catch (\Exception $e) { FeedMePlugin::log('Tried to attach debug logs to a support request and something went horribly wrong: ' . $e->getMessage(), LogLevel::Warning, true); } $email = new EmailModel(); $email->fromEmail = $getHelpModel->fromEmail; $email->toEmail = "*****@*****.**"; $email->subject = "Feed Me Support"; $email->body = $message; if ($zipFile) { $email->addAttachment($zipFile, 'FeedMeSupportAttachment.zip', 'base64', 'application/zip'); } $result = craft()->email->sendEmail($email); if ($result) { if ($zipFile) { if (IOHelper::fileExists($zipFile)) { IOHelper::deleteFile($zipFile); } } if ($tempFolder) { IOHelper::clearFolder($tempFolder); IOHelper::deleteFolder($tempFolder); } $success = true; } else { $errors = array('Support' => array('Unable to contact support. Please try again soon.')); } } else { $errors = $getHelpModel->getErrors(); } $this->returnJson(array('success' => $success, 'errors' => $errors)); }
/** * @param EmailModel $email * @param AssetFileModel[] $assets */ protected function attachAssetFilesToEmailModel(EmailModel $email, array $assets) { foreach ($assets as $asset) { $name = $asset->filename; $path = $this->getAssetFilePath($asset); $email->addAttachment($path, $name); } }
/** * * GET Parameters: * - appId - Id of the app trying to relay the message * - appSecret - App Secret to authenticate the App * - userId - Either a valid email or a user id * * @todo Introduce email permissions for certain applications * @param int $userid Deprecated, do not use * @throws PublicException * @throws Exception * @throws HTTPMethodException */ public function send($userid = null) { //TODO: Add search by username try { #Check if the request is post and subject and body are not empty if (!$this->request->isPost()) { throw new HTTPMethodException(); } /* * Retrieve the email / userId from the request. This should either be posted * or getted. */ $userid = isset($_GET['to']) ? $_GET['to'] : _def($_POST['to'], $userid); /* * We check whether we received any data at all via POST for the recipient. * We can obviously not relay any email to any user if we don't know where * to send it to. */ if (!$userid) { throw new PublicException('This enpoint requires a recipient'); } /* * Get the application authorizing the email. Although we do not log this * right now, it's gonna be invaluable to help determining whether an app * was compromised and is sending garbage. */ if (!$this->token) { $app = db()->table('authapp')->get('appID', $_GET['appId'])->addRestriction('appSecret', $_GET['appSecret'])->fetch(); } else { $app = $this->token->app; } if (!$app) { throw new Exception('Could not authenticate the application trying to send the email'); } /* * Determine what kind of id you were sent to determine where to send the * email to. */ if (filter_var($userid, FILTER_VALIDATE_EMAIL)) { $email = $userid; } elseif (is_numeric($userid)) { $user = db()->table('user')->get('_id', _def($_POST['to'], $userid))->fetch(); $email = $user->email; } $vsubject = validate()->addRule(new EmptyValidationRule('Subject cannot be empty')); $vcontent = validate()->addRule(new EmptyValidationRule('Message body cannot be empty')); validate($vsubject->setValue($_POST['subject']), $vcontent->setValue($_POST['body'])); #Create the message and put it into the message queue EmailModel::queue($email, $vsubject->getValue(), $vcontent->getValue())->store(); #Everything was okay - that's it. The email will be delivered later } catch (ValidationException $e) { $this->view->set('errors', $e->getResult()); } catch (HTTPMethodException $e) { //Do nothing, we'll serve it with get } }
/** * * @template none */ public function index() { //TODO: Add file locking mechanism EmailModel::deliver(); }
public function activate($tokenid = null) { $token = $tokenid ? db()->table('token')->get('token', $tokenid)->fetch() : null; #The token should have been created by the Auth Server if ($token && $token->app !== null) { throw new PublicException('Token level insufficient', 403); } if ($token) { $token->user->verified = 1; $token->user->store(); } else { $token = TokenModel::create(null, 1800, false); $token->user = $this->user; $token->store(); $url = new absoluteURL('user', 'activate', $token->token); EmailModel::queue($this->user->email, 'Activate your account', sprintf('Click here to activate your account: <a href="%s">%s</a>', $url, $url)); } #We need to redirect the user back to the home page $this->response->getHeaders()->redirect(new URL(array('message' => 'success'))); }
/** * Send Email Notification * */ public function sendEmailNotification($form, $postUploads, $postData, $customSubject, $message, $html = true, $email = null) { $errors = false; $attributes = $form->getAttributes(); $notificationSettings = $attributes['notificationSettings']; $toEmails = ArrayHelper::stringToArray($notificationSettings['emailSettings']['notifyEmail']); // Process Subject Line if ($customSubject) { $subject = $customSubject; } else { $subject = $notificationSettings['emailSettings']['emailSubject']; } // If submission has files if ($postUploads) { $fileAttachments = []; foreach ($postUploads as $file) { $fileAttachments[] = craft()->assets->getFileById($file); } } foreach ($toEmails as $toEmail) { $email = new EmailModel(); $emailSettings = craft()->email->getSettings(); $email->fromEmail = $emailSettings['emailAddress']; $email->replyTo = $emailSettings['emailAddress']; $email->sender = $emailSettings['emailAddress']; $email->fromName = $form->name; $email->toEmail = $toEmail; $email->subject = $subject; $email->body = $message; // Attach files to email if (!empty($fileAttachments)) { foreach ($fileAttachments as $attachment) { if ($attachment) { $email->addAttachment($attachment->getUrl(), $attachment->title, 'base64', $attachment->getMimeType()); } } } if (!craft()->email->sendEmail($email)) { $errors = true; } } return $errors ? false : true; }
public function email_notifications() { if (\WebAPL\Modules::checkInstance('person')) { $events = \CalendarModel::join(CalendarLangModel::getTableName(), \CalendarModel::getField('id'), '=', CalendarLangModel::getField('calendar_item_id'))->join(\CalendarGroup::getTableName(), \CalendarGroup::getField('id'), '=', \CalendarModel::getField('calendar_group_id'))->join(\CalendarPostModel::getTableName(), \CalendarPostModel::getField('calendar_group_id'), '=', \CalendarGroup::getField('id'))->where(CalendarLangModel::getField('lang_id'), \WebAPL\Language::getId())->where(\CalendarModel::getField('enabled'), 1)->where(\CalendarModel::getField('person_id'), '<>', 0)->select(CalendarLangModel::getField("*"), \CalendarModel::getField('event_date'), \CalendarModel::getField('repeat_frequency'), \CalendarModel::getField('repeat_to_date'), \CalendarModel::getField('person_id'), \CalendarModel::getField('post_id'), \CalendarModel::getField('period'))->orderBy(\CalendarModel::getField('event_date'), 'asc')->where(function ($query) { $query->where(function ($query) { $query->where(DB::raw("DATE(" . CalendarModel::getField('event_date') . ")"), '=', DB::raw('DATE(CURRENT_TIMESTAMP)')); })->orWhere(function ($query) { $query->where(\CalendarModel::getField('event_date'), '<=', DB::raw('CURRENT_TIMESTAMP'))->where(\CalendarModel::getField('repeat_to_date'), '>=', DB::raw('CURRENT_TIMESTAMP'))->where(\CalendarModel::getField('repeat_frequency'), '<>', 'none'); }); })->get(); $event_list = \CalendarModel::generateEvents($events, false); $today_events = []; foreach ($event_list as $event) { if (date("Y-m-d", strtotime($event['event_date'])) === date("Y-m-d") && strtotime($event['event_date']) >= time()) { echo " sendone "; $today_events[] = $event; $this->loadClass(['PersonModel'], 'person'); $person = \PersonModel::getPerson($event['person_id']); if (isset($person->email) && $person->email) { Template::viewModule($this->module_name, function () use($person, $event) { \EmailModel::sendToAddress($person->email, "Do you have an event today", 'views.calendarEmail', ['person' => $person, 'event' => $event]); }); } } } } }
/** * Send Email Notification * */ public function sendEmailNotification($form, $files, $postData, $customEmail, $customSubject, $message, $html = true, $email = null) { $errors = false; $attributes = $form->getAttributes(); $notificationSettings = $attributes['notificationSettings']; $toEmails = ArrayHelper::stringToArray($notificationSettings['emailSettings']['notifyEmail']); $emailSettings = craft()->email->getSettings(); if (isset($notificationSettings['replyTo']) && $notificationSettings['replyTo'] != '') { $replyTo = $postData[$notificationSettings['replyTo']]; } else { $replyTo = $emailSettings['emailAddress']; } // Process Subject Line if ($customSubject) { $subject = $customSubject; } else { $subject = $notificationSettings['emailSettings']['emailSubject']; } if ($customEmail != '') { $theEmailAddress = explode('|', $customEmail); ArrayHelper::prependOrAppend($toEmails, $theEmailAddress[0], true); } foreach ($toEmails as $toEmail) { $email = new EmailModel(); $email->fromEmail = $emailSettings['emailAddress']; $email->replyTo = $replyTo; $email->sender = $emailSettings['emailAddress']; $email->fromName = $form->name; $email->toEmail = $toEmail; $email->subject = $subject; $email->htmlBody = $message; // Attach files to email if (!empty($files)) { foreach ($files as $attachment) { $email->addAttachment($attachment['tempPath'], $attachment['filename'], 'base64', $attachment['type']); } } if (!craft()->email->sendEmail($email)) { $errors = true; } } return $errors ? false : true; }
public function actionSendMail() { //Get plugin settings $settings = craft()->plugins->getPlugin('commerceMailer')->getSettings(); //Called via Ajax? $ajax = craft()->request->isAjaxRequest(); //Settings to control behavour when testing - we don't want to debug via ajax or it stuffs up the JSON response... $debugPOST = ($settings->debugPOST and !$ajax); $emailing = $settings->emailing; $savedBody = false; //Must be called by POST $this->requirePostRequest(); //We'll return all the POST data to the template, so kick of our return data with that... $vars = craft()->request->getPost(); //Dump POST to page if debugging if ($debugPOST) { echo '<h3>POST</h3><pre>'; print_r($vars); echo '</pre>'; } //Is this spam? Assume false. $spam = false; $spam = !$this->validateHoneypot($settings->honeypotField); //If it's an internal email, make sure it's in the whitelist of names $emailWhitelist = array_map('trim', explode(',', $settings->whitelistedNames)); if ($debugPOST) { echo '<h3>Whitelist</h3><pre>'; print_r($emailWhitelist); echo '</pre>'; } if (isset($vars['internalName'])) { if ($vars['internalName'] != "") { $spam = $spam && in_array($vars['internalName'], $emailWhitelist); if (!$spam) { $vars['toEmail'] = $vars['internalName'] . "@" . $settings->internalDomain; } } } //hold a list of possible errors to pass back to template on error $errors = array(); //Deal with extra fields...the message input might be just a message, or have other fields //Pinched from P & T ContactForm $postedMessage = craft()->request->getPost('message'); if ($postedMessage) { if (is_array($postedMessage)) { $savedBody = false; if (isset($postedMessage['body'])) { // Save the message body in case we need to reassign it in the event there's a validation error $savedBody = $postedMessage['body']; } // If it's false, then there was no messages[body] input submitted. If it's '', then validation needs to fail. if ($savedBody === false || $savedBody !== '') { // Compile the message from each of the individual values $compiledMessage = ''; foreach ($postedMessage as $key => $value) { if ($key != 'body') { if ($compiledMessage) { $compiledMessage .= "<br><br>"; } $compiledMessage .= $key . ': '; if (is_array($value)) { $compiledMessage .= implode(', ', $value); } else { $compiledMessage .= $value; } } } if (!empty($postedMessage['body'])) { if ($compiledMessage) { $compiledMessage .= "<br><br>"; } $compiledMessage .= $postedMessage['body']; } $vars['body'] = $compiledMessage; } } else { $vars['body'] = $postedMessage; } } // create an EmailModel & populate it $email = EmailModel::populateModel($vars); //validate the email model //put all our errors in one place, and return the email model if invalid - use message as this is what contactForm does $valid = $email->validate(); if (!$valid) { if ($savedBody !== false) { $vars['message'] = $savedBody; } foreach ($email->getAllErrors() as $key => $error) { $errors[] = $error; } } // Product, order and cart data if (isset($vars['productId'])) { $vars['product'] = craft()->commerce_products->getProductById($vars['productId']); } if (isset($vars['orderId'])) { $vars['order'] = craft()->commerce_orders->getOrderById($vars['orderId']); } $vars['cart'] = craft()->commerce_cart->getCart(); //Actual template to load is built by using the settings templateFolder + the form's POST var with name 'template' $templateFolder = $settings->templateFolder; if (!isset($templateFolder)) { $errors[] = 'No template folder in Commerce Mailer settings'; } if (!isset($vars['template'])) { $errors[] = 'No template in POST'; } //@TODO - what to do about the plain text body - will be unrendered...? if (isset($templateFolder) and isset($vars['template']) and !$errors) { // parse the html template $htmlBody = craft()->templates->render($templateFolder . "/" . $vars['template'], $vars); if ($debugPOST) { print "<h4>Subject: " . $vars['subject'] . "</h4>"; print $htmlBody; } $email->htmlBody = $htmlBody; } //OK, actually do something....unless we have an error.... if ($errors) { $errors[] = 'Email not sent.'; foreach ($errors as $error) { CommerceMailerPlugin::logError($error); } craft()->urlManager->setRouteVariables(['errors' => $errors, 'message' => $email]); } else { if ($emailing) { $sent = false; //attempt to send the email if (!$spam) { //Special sauce for us.... if (craft()->config->get('environmentVariables')['customMessaging']) { //Are we sending to a local address? if (strpos($email->toEmail, "@" . $settings->internalDomain) === false) { //No - we'll MAY NEED to later resort to phpmail send this sucker out now that transactional email //services won't allow univerified sending domains :( ... However this is working with mailgun currently... $sent = craft()->businessLogic_messaging->sendCraftEmail($email->fromEmail, $email->toEmail, $email->subject, $email->htmlBody); } else { //Make a freshdesk ticket with the API $sent = craft()->businessLogic_freshdesk->ticket($email->fromEmail, $email->toEmail, $email->subject, $email->htmlBody, isset($vars['order']) ? $vars['order'] : null); } } else { $sent = craft()->email->sendEmail($email); } } else { CommerceMailerPlugin::log('CommerceMailer spam trapped an email to : ' . $vars['toEmail']); // but we pretend we've sent it... $sent = true; } //we tried to send an email, log error if there was one... if (!$sent) { $errors[] = 'Sending email failed.'; CommerceMailerPlugin::logError('Sending email failed.'); craft()->urlManager->setRouteVariables(['errors' => $errors, 'message' => $email]); } else { craft()->userSession->setFlash('notice', 'CommerceMailer has sent an email to : ' . $vars['toEmail']); CommerceMailerPlugin::log('CommerceMailer has sent an email to : ' . $vars['toEmail']); } } else { if (!$spam) { CommerceMailerPlugin::logError('CommerceMailer would have has sent an email to : ' . $vars['toEmail']); } else { CommerceMailerPlugin::logError('CommerceMailer would have spam trapped an email to : ' . $vars['toEmail']); } } //only redirect on non ajax calls and if debugging isn't enabled. if (!$debugPOST and !$ajax) { $this->redirectToPostedUrl(); } } if ($debugPOST and $errors) { echo '<h3>ERRORS</h3><pre>'; print_r($errors); echo '</pre>'; echo '<h3>MESSAGE</h3><pre>'; print_r($vars['message']); echo '</pre>'; } // Appropriate Ajax responses... if ($ajax) { if ($errors) { $this->returnErrorJson($errors); } else { $this->returnJson(["success" => true]); } } }
/** * Email a submission. * * @param AmForms_SubmissionModel $submission * @param mixed $overrideRecipients [Optional] Override recipients from form settings. * * @return bool */ public function emailSubmission(AmForms_SubmissionModel $submission, $overrideRecipients = false) { // Do we even have a form ID? if (!$submission->formId) { return false; } // Get form if not already set $submission->getForm(); $form = $submission->form; $submission->formName = $form->name; if (!$form->notificationEnabled) { return false; } // Get our recipients $recipients = ArrayHelper::stringToArray($form->notificationRecipients); // Send copy? if ($form->sendCopy) { $sendCopyTo = $submission->{$form->sendCopyTo}; if (filter_var($sendCopyTo, FILTER_VALIDATE_EMAIL)) { $recipients[] = $sendCopyTo; } } if ($overrideRecipients !== false) { if (is_array($overrideRecipients) && count($overrideRecipients)) { $recipients = $overrideRecipients; } elseif (is_string($overrideRecipients)) { $recipients = ArrayHelper::stringToArray($overrideRecipients); } } $recipients = array_unique($recipients); if (!count($recipients)) { return false; } // Overridden recipients skips before email event, so by default, send the email! $sendEmail = true; // Fire an 'onBeforeEmailSubmission' event if ($overrideRecipients === false) { $event = new Event($this, array('submission' => $submission)); $this->onBeforeEmailSubmission($event); // Override sendEmail $sendEmail = $event->performAction; } // Is the event giving us the go-ahead? if ($sendEmail) { // Get email body $body = $this->getSubmissionEmailBody($submission); // Other email attributes $subject = Craft::t($form->notificationSubject); if ($form->notificationSubject) { $subject = craft()->templates->renderObjectTemplate($form->notificationSubject, $submission); } if ($form->notificationReplyToEmail) { $replyTo = craft()->templates->renderObjectTemplate($form->notificationReplyToEmail, $submission); if (!filter_var($replyTo, FILTER_VALIDATE_EMAIL)) { $replyTo = null; } } // Start mailing! $success = false; // @TODO Mandrill $email = new EmailModel(); $email->htmlBody = $body; $email->fromEmail = $form->notificationSenderEmail; $email->fromName = $form->notificationSenderName; $email->subject = $subject; if ($replyTo) { $email->replyTo = $replyTo; } // Add Bcc? $bccEmailAddress = craft()->amForms_settings->getSettingsByHandleAndType('bccEmailAddress', AmFormsModel::SettingGeneral); if ($bccEmailAddress && $bccEmailAddress->value) { $bccAddresses = ArrayHelper::stringToArray($bccEmailAddress->value); $bccAddresses = array_unique($bccAddresses); if (count($bccAddresses)) { $properBccAddresses = array(); foreach ($bccAddresses as $bccAddress) { $bccAddress = craft()->templates->renderObjectTemplate($bccAddress, $submission); if (filter_var($bccAddress, FILTER_VALIDATE_EMAIL)) { $properBccAddresses[] = array('email' => $bccAddress); } } if (count($properBccAddresses)) { $email->bcc = $properBccAddresses; } } } // Add files to the notification? if ($form->notificationFilesEnabled) { foreach ($submission->getFieldLayout()->getTabs() as $tab) { // Tab fields $fields = $tab->getFields(); foreach ($fields as $layoutField) { // Get actual field $field = $layoutField->getField(); // Find assets if ($field->type == 'Assets') { foreach ($submission->{$field->handle}->find() as $asset) { $assetPath = craft()->amForms->getPathForAsset($asset); // Add asset as attachment if (IOHelper::fileExists($assetPath . $asset->filename)) { $email->addAttachment($assetPath . $asset->filename); } } } } } } // Send emails foreach ($recipients as $recipient) { $email->toEmail = craft()->templates->renderObjectTemplate($recipient, $submission); if (filter_var($email->toEmail, FILTER_VALIDATE_EMAIL)) { // Add variable for email event if (craft()->email->sendEmail($email, array('amFormsSubmission' => $submission))) { $success = true; } } } // Fire an 'onEmailSubmission' event $this->onEmailSubmission(new Event($this, array('success' => $success, 'submission' => $submission))); return $success; } return false; }
/** * @param SproutEmail_EntryModel $entry * @param SproutEmail_CampaignModel $campaign * * @throws \Exception * * @return bool */ public function exportEntry(SproutEmail_EntryModel $entry, SproutEmail_CampaignModel $campaign) { if ($campaign->isNotification()) { try { return $this->sendMockNotification($entry, $campaign); } catch (\Exception $e) { throw $e; } } $params = array('entry' => $entry, 'campaign' => $campaign); $email = array('fromEmail' => $entry->fromEmail, 'fromName' => $entry->fromName, 'subject' => $entry->subjectLine); if ($entry->replyTo && filter_var($entry->replyTo, FILTER_VALIDATE_EMAIL)) { $email['replyTo'] = $entry->replyTo; } $recipients = array(); if ($entryRecipientLists = SproutEmail_EntryRecipientListRecord::model()->findAllByAttributes(array('entryId' => $entry->id))) { foreach ($entryRecipientLists as $entryRecipientList) { if ($recipientList = $this->getRecipientListById($entryRecipientList->list)) { $recipients = array_merge($recipients, $recipientList->recipients); } } } $email = EmailModel::populateModel($email); foreach ($recipients as $recipient) { try { $params['recipient'] = $recipient; $email->body = sproutEmail()->renderSiteTemplateIfExists($campaign->template . '.txt', $params); $email->htmlBody = sproutEmail()->renderSiteTemplateIfExists($campaign->template, $params); $email->setAttribute('toEmail', $recipient->email); $email->setAttribute('toFirstName', $recipient->firstName); $email->setAttribute('toLastName', $recipient->lastName); craft()->email->sendEmail($email); } catch (\Exception $e) { throw $e; } } }
require_once('class.phpmailer.php'); include_once'emailModel.php'; include_once'emailView.php'; $author = $_POST['author']; $agency = $_POST['agency']; $email = new emailModel(); $resultIds = $email->loadIds(); $resultEmails = $email->loadEmail($agency); $receiverEmails = ""; $subject = "BOLO Alert"; $view = new Email_View(); $model = new EmailModel(); $data = $model->getlast(); $result = $data->fetch_assoc(); $id = $result['bolo_id']; $path= ' <a href="http://bolo.cs.fiu.edu/bolofliercreator/?page_id=1488&idBolo=' . "$id" . '">here</a>'; $file = 'uploads/preview' . $author . '.pdf'; $file_size = filesize($file); $mail = new PHPMailer(); // defaults to using php "mail()" //add all email addresses to send to
public function sendReceiptEmail() { if (Efiwebsetting::getData('checkOAuth') == 'yes') { IMBAuth::checkOAuth(); } $email = addslashes($_GET['email']); $user_id = addslashes($_GET['user_id']); if ($email == "") { $user = new UserModel(); $user->getByID($user_id); $email = $user->email; } $order_id = isset($_GET['id_order']) ? addslashes($_GET['id_order']) : die("Please fill order id"); $receipt = "<table>"; $orderDetails = $this->getReceiptDetail(1); pr($orderDetails['Order Details']); foreach ($orderDetails['Order Details'] as $detail) { $receipt .= "<tr>\n <td>" . $detail['name_dish'] . "</td>\n <td>" . $detail['quantity'] . "</td>\n</tr>"; } $receipt .= "</table>"; $emailModel = new EmailModel(); $emailModel->getByID("receiptOrder"); // pr($emailModel); echo $emailModel->sendEmail($email, array("resto_name" => $order_id, "receipt" => $receipt)); die; }
function dapatKomisiTingTong($email, $commision_value, $isPending, $client_username, $isAgent) { $text = ''; if (!$isAgent) { $text = "Please complete your Agent registration <a href='" . _BPATH . "marketer'>here</a>."; } $pendingText = ''; if ($isPending) { $pendingText = "To complete the pair, please deal paid Apps"; } $emailModel = new EmailModel(); $emailModel->getByID("dapatKomisiTingTong"); return $emailModel->sendEmail($email, array("commision_value" => $commision_value, "is_Agent" => $text, "is_Pending_Free" => $pendingText, "link_more_sales" => _BPATH . "link_more_sales")); }
public function sendUsingModel($identifier, $toEmail, $toName = '', $data = []) { $email = new EmailModel(); if ($email->loadByField('identifier', $identifier)) { $template = $email->getTemplate(); $fromName = $email->getFromName(); $fromEmail = $email->getFromEmail(); $subject = $this->replaceData($template->getSubject(), $data); $markup = $this->rel2abs($this->replaceData($template->getMarkup(), $data)); $body = PHP_EOL . $this->rel2abs($this->replaceData($template->getContent($markup), $data)); // reset recipients $this->clearAllRecipients(); // to $this->addAddress($toEmail, $toName); // from $this->From = $fromEmail; // fromName $this->FromName = $fromName; // subject $this->Subject = $subject; // utf8 please $this->CharSet = 'utf-8'; // body $this->msgHTML($body); // send! $status = $this->send(); // log if (class_exists('MailerlogModel')) { MailerlogModel::log($fromEmail, $fromName, $toEmail, $toName, $subject, $body, $status ? 1 : 0); } return $status; } else { throw new Ajde_Exception('Email with identifier ' . $identifier . ' not found'); } }