Example #1
0
File: Mail.php Project: nabble/ajde
 public function publish()
 {
     $mailer = new Ajde_Mailer();
     $mailer->From = config('app.email');
     $mailer->FromName = config('app.title');
     $mailer->Subject = $this->getTitle();
     $mailer->Body = $this->getMessage() . PHP_EOL . PHP_EOL . $this->getUrl();
     $mailer->AltBody = strip_tags($mailer->Body);
     $mailer->isHTML(true);
     $count = 0;
     foreach ($this->_recipients as $to) {
         $mailer->clearAllRecipients();
         $mailer->addAddress($to);
         if ($mailer->send()) {
             $count++;
         }
     }
     return "javascript:alert('Message sent as e-mail to " . $count . " recipients');";
 }
Example #2
0
 private function submission($crudId, $id)
 {
     $session = new Ajde_Session('AC.Crud');
     /* @var $crud Ajde_Crud */
     $crud = $session->getModel($crudId);
     // verify that we have a valid crud model
     if (!$crud) {
         return ['success' => false];
     }
     /* @var $model FormModel */
     $model = $crud->getModel();
     $model->setOptions($crud->getOptions('model'));
     // Get POST params
     $post = Ajde_Http_Request::globalPost();
     $id = issetor($post['id']);
     // verify that we have a valid form model
     if (!$id) {
         return ['success' => false];
     }
     // load form
     $model->loadByPK($id);
     $model->populate($post);
     // validate form
     Ajde_Event::trigger($model, 'beforeCrudSave', [$crud]);
     if (!$model->validate($crud->getOptions('fields'))) {
         return ['operation' => 'save', 'success' => false, 'errors' => $model->getValidationErrors()];
     }
     // prepare submission
     $values = [];
     foreach ($post as $key => $value) {
         if (substr($key, 0, 5) === 'meta_') {
             $metaId = str_replace('meta_', '', $key);
             $metaName = MetaModel::getNameFromId($metaId);
             $values[$metaName] = $value;
         }
     }
     $entryText = '';
     foreach ($values as $k => $v) {
         $entryText .= $k . ': ' . $v . PHP_EOL;
     }
     $submission = new SubmissionModel();
     $submission->form = $id;
     $submission->ip = $_SERVER['REMOTE_ADDR'];
     $submission->user = Ajde_User::getLoggedIn();
     $submission->entry = json_encode($values);
     $submission->entry_text = $entryText;
     $success = $submission->insert();
     if ($success === true) {
         // Destroy reference to crud instance
         $session->destroy($crudId);
         // set message for next page
         Ajde_Session_Flash::alert(trans('Form submitted successfully'));
         $mailer = new Ajde_Mailer();
         // send email to administrator
         $body = 'Form: ' . $model->displayField() . '<br/><br/>' . nl2br($entryText);
         $mailer->SendQuickMail(config('app.email'), config('app.email'), config('app.title'), 'New form submission', $body);
         // send email to user
         $email = $model->getEmail();
         /* @var $email EmailModel */
         $email_to = $model->getEmailTo();
         /* @var $email MetaModel */
         $email_address = issetor($post['meta_' . $email_to->getPK()]);
         if ($email->hasLoaded() && $email_to->hasLoaded() && $email_address) {
             $mailer->sendUsingModel($email->getIdentifier(), $email_address, $email_address, ['entry' => nl2br($entryText)]);
         }
     }
     return ['operation' => 'save', 'id' => $model->getPK(), 'displayField' => $model->get($model->getDisplayField()), 'success' => $success];
 }
 /**
  * @param TransactionItemModel $transaction
  *
  * @deprecated use mailUser
  *
  * @throws Ajde_Core_Exception_Deprecated
  * @throws Ajde_Exception
  * @throws Exception
  * @throws phpmailerException
  */
 public function mailUserDeprecated(TransactionItemModel $transaction)
 {
     throw new Ajde_Core_Exception_Deprecated();
     $mailer = new Ajde_Mailer();
     $mailer->IsMail();
     // use php mail()
     $mailer->AddAddress($transaction->email, $transaction->name);
     $mailer->From = config('app.email');
     $mailer->FromName = config('app.title');
     $mailer->Subject = 'Your order';
     $mailer->Body = '<h2>Your order on ' . config('app.title') . '</h2>' . '<p>Thank you for shopping with us. We will ship your items as soon as possible if you chose for delivery.<br/>' . 'To view the status of your order, please click this link:</p>' . '<p><a href=\'' . config('app.rootUrl') . 'shop/transaction:view/' . $transaction->secret . '.html\'>View your order status</a></p>' . '<p>Hope to welcome you again soon on <a href=\'' . config('app.rootUrl') . '\'>' . config('app.title') . '</a></p>';
     $mailer->IsHTML(true);
     if (!$mailer->Send()) {
         Ajde_Log::log('Mail to ' . $transaction->email . ' failed');
     }
 }
Example #4
0
 public function sendResetMail($hash)
 {
     $resetLink = config('app.rootUrl') . 'user/reset?h=' . $hash;
     $mailer = new Ajde_Mailer();
     $mailer->sendUsingModel('user_reset_link', $this->getEmail(), $this->getFullname(), ['resetlink' => $resetLink]);
 }