Ejemplo n.º 1
0
 public function add()
 {
     $user = $this->Users->newEntity();
     if ($this->request->is('post')) {
         $user = $this->Users->patchEntity($user, $this->request->data);
         if ($this->Users->save($user)) {
             $this->Flash->success(__("L'utilisateur a été sauvegardé."));
             $email = new Email('gmail');
             $email->from(['*****@*****.**' => 'LeBonCoup'])->emailFormat('html')->to($user->email)->subject('Welcome ' . $user->prenom)->send('Bienvenu sur le site LeBonCoup,
                         <br>
                         Vous avez bien été enregistré sur le LeBonCoup
                         <br>
                         Votre nom utilisateur est: ' . $user->username . ' 
                         <br>
                         Cliquez sur ce lien pour valider votre compte <a href="http://comdfran.fr/leboncoup/users/validatemail/' . $user->email . '">validation</a>
                         <br>
                         Copier coller dans votre navigateur http://comdfran.fr/leboncoup/users/validatemail/' . $user->email . '
                         <br>
                         Cordialement,');
             return $this->redirect(['controller' => 'Pages', 'action' => 'display', 'home']);
         }
         $this->Flash->error(__("Impossible d'ajouter l'utilisateur."));
     }
     $this->set('user', $user);
 }
Ejemplo n.º 2
0
 protected function _execute(array $data)
 {
     $email = new Email();
     $email->profile('default');
     $email->from([$data['email']])->to('*****@*****.**')->subject('Web Site Contact Form')->send([$data['body']]);
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Send mail
  *
  * @param \Cake\Mailer\Email $email Email instance.
  * @return array
  */
 public function send(Email $email)
 {
     $this->transportConfig = Hash::merge($this->transportConfig, $this->_config);
     $message = ['html' => $email->message(Email::MESSAGE_HTML), 'text' => $email->message(Email::MESSAGE_TEXT), 'subject' => mb_decode_mimeheader($email->subject()), 'from' => key($email->from()), 'fromname' => current($email->from()), 'to' => [], 'toname' => [], 'cc' => [], 'ccname' => [], 'bcc' => [], 'bccname' => [], 'replyto' => array_keys($email->replyTo())[0]];
     // Add receipients
     foreach (['to', 'cc', 'bcc'] as $type) {
         foreach ($email->{$type}() as $mail => $name) {
             $message[$type][] = $mail;
             $message[$type . 'name'][] = $name;
         }
     }
     // Create a new scoped Http Client
     $this->http = new Client(['host' => 'api.sendgrid.com', 'scheme' => 'https', 'headers' => ['User-Agent' => 'CakePHP SendGrid Plugin']]);
     $message = $this->_attachments($email, $message);
     return $this->_send($message);
 }
Ejemplo n.º 4
0
 /**
  * Displays a view
  *
  * @return void|\Cake\Network\Response
  * @throws \Cake\Network\Exception\NotFoundException When the view file could not
  *   be found or \Cake\View\Exception\MissingTemplateException in debug mode.
  */
 public function display()
 {
     $path = func_get_args();
     $count = count($path);
     if (!$count) {
         return $this->redirect('/');
     }
     $page = $subpage = null;
     if (!empty($path[0])) {
         $page = $path[0];
     }
     if (!empty($path[1])) {
         $subpage = $path[1];
     }
     $this->set(compact('page', 'subpage'));
     try {
         $this->render(implode('/', $path));
     } catch (MissingTemplateException $e) {
         if (Configure::read('debug')) {
             throw $e;
         }
         throw new NotFoundException();
     }
     // Contact Form
     if ($this->request->is('post')) {
         $email = new Email();
         $email->from(['*****@*****.**' => 'My Site'])->to('*****@*****.**')->subject('About')->send('My message');
         $this->Flash->success(__('The request has been saved.'));
     }
 }
Ejemplo n.º 5
0
 public function preview($e)
 {
     $configName = $e['config'];
     $template = $e['template'];
     $layout = $e['layout'];
     $headers = empty($e['headers']) ? [] : (array) $e['headers'];
     $theme = empty($e['theme']) ? '' : (string) $e['theme'];
     $email = new Email($configName);
     if (!empty($e['attachments'])) {
         $email->attachments($e['attachments']);
     }
     $email->transport('Debug')->to($e['email'])->subject($e['subject'])->template($template, $layout)->emailFormat($e['format'])->addHeaders($headers)->theme($theme)->messageId(false)->returnPath($email->from())->viewVars($e['template_vars']);
     $return = $email->send();
     $this->out('Content:');
     $this->hr();
     $this->out($return['message']);
     $this->hr();
     $this->out('Headers:');
     $this->hr();
     $this->out($return['headers']);
     $this->hr();
     $this->out('Data:');
     $this->hr();
     debug($e['template_vars']);
     $this->hr();
     $this->out();
 }
Ejemplo n.º 6
0
 protected function setupEmail(Email $email)
 {
     $this->sendgridEmail = new \SendGrid\Email();
     foreach ($email->to() as $e => $n) {
         $this->sendgridEmail->addTo($e, $n);
     }
     foreach ($email->cc() as $e => $n) {
         $this->sendgridEmail->addCc($e, $n);
     }
     foreach ($email->bcc() as $e => $n) {
         $this->sendgridEmail->addBcc($e, $n);
     }
     foreach ($email->from() as $e => $n) {
         $this->sendgridEmail->setFrom($e);
         $this->sendgridEmail->setFromName($n);
     }
     $this->sendgridEmail->setSubject($email->subject());
     $this->sendgridEmail->setText($email->message(Email::MESSAGE_TEXT));
     $this->sendgridEmail->setHtml($email->message(Email::MESSAGE_HTML));
     if ($email->attachments()) {
         foreach ($email->attachments() as $attachment) {
             $this->sendgridEmail->setAttachment($attachment['file'], $attachment['custom_filename']);
         }
     }
 }
Ejemplo n.º 7
0
 public function smtp()
 {
     $email = new Email('default');
     $email->from(['*****@*****.**' => 'Tienda Online'])->to('*****@*****.**')->subject('Correo desde CakePHP 3')->send('Contenido del correo ...');
     echo 'Correo enviado';
     $this->autoRender = false;
 }
 /**
  * Test configuration
  *
  * @return void
  */
 public function testInvalidConfig()
 {
     $this->setExpectedException('SparkPostEmail\\Mailer\\Exception\\MissingCredentialsException');
     $this->SparkPostTransport->config($this->invalidConfig);
     $email = new Email();
     $email->transport($this->SparkPostTransport);
     $email->from(['*****@*****.**' => 'CakePHP SparkPost'])->to('*****@*****.**')->subject('This is test subject')->emailFormat('text')->send('Testing Maingun');
 }
Ejemplo n.º 9
0
 protected function _execute(array $data)
 {
     // Send an email.
     Email::configTransport('amazon', ['host' => 'email-smtp.us-east-1.amazonaws.com', 'port' => 587, 'username' => 'AKIAJARRU5LPFHEQHKPQ', 'password' => 'AmNFFJsVG8vQGHqlXgy9nMYj9eAx2ubZ/Ghb84FVm7PC', 'className' => 'Smtp', 'tls' => true]);
     $email = new Email('default');
     $email->from(['*****@*****.**' => 'My Site'])->to('*****@*****.**')->subject('About')->send('My message');
     return true;
 }
 private function sendEmailAfterEnroll($name, $email)
 {
     $message = 'Olá, ' . $name . '<br /><br />';
     $message .= 'Ficamos muito felizes por sua participação no sorteio da inscrição Silver para o PHP Conference Brasil.<br />';
     $message .= 'Acompanhe-nos pelo site <a href="http://phppr.net">http://phppr.net</a> para acompanhar nosso trabalho e ficar sabendo mais informações a respeito deste sorteio.<br />';
     $message .= '<br />Desde já lhe desejamos BOA SORTE!!!';
     $mailer = new Email('default');
     $mailer->from(['*****@*****.**' => 'PHP PR'])->to($email, $name)->subject('Sorteio PHP PR')->emailFormat('html')->send($message);
 }
Ejemplo n.º 11
0
 /**
  * @param $data
  */
 public function passwordChangedEmail($data)
 {
     $app = new AppController();
     $subject = 'Password Changed - ' . $app->appsName;
     $email = new Email('mandril');
     $user = array('to' => $data['username'], 'name' => $data['profile']['first_name'] . ' ' . $data['profile']['last_name']);
     $data = array('user' => $user, 'appName' => $app->appsName);
     $email->from([$app->emailFrom => $app->appsName])->to($user['to'])->subject($subject)->theme($app->currentTheme)->template('changed_password')->emailFormat('html')->set(['data' => $data])->send();
 }
Ejemplo n.º 12
0
 protected function _execute(array $data)
 {
     $email = new Email('default');
     $email->from(['*****@*****.**' => 'EnTec 2016'])->emailFormat('html')->replyTo('*****@*****.**', 'EnTec 2016')->subject('[EntTec 2016] ' . $data['assunto']);
     $destinatarios = $data['destinatarios'];
     for ($i = 0, $c = count($destinatarios); $i < $c; $i++) {
         $email->addBcc($destinatarios[$i]['email'], $destinatarios[$i]['nome']);
     }
     $email->send($data['corpo']);
     return true;
 }
Ejemplo n.º 13
0
 /**
  * mailer method
  *
  * @param array $data Dados para formar o email.
  * @return boolean True ou False.
  */
 public function mailer($data, $template, $subject)
 {
     $email = new Email();
     $email->transport('mailSgl');
     $email->emailFormat('html');
     $email->template($template);
     $email->from('*****@*****.**', 'SGL');
     $email->to($data['email'], $data['nome']);
     $email->viewVars($data);
     $email->subject($subject);
     $email->send();
 }
 /**
  * TestSend method
  *
  * @return void
  */
 public function testSendWithEmail()
 {
     $config = ['transport' => 'queue', 'charset' => 'utf-8', 'headerCharset' => 'utf-8'];
     $this->QueueTransport->config($config);
     $Email = new Email($config);
     $Email->from('*****@*****.**', 'CakePHP Test');
     $Email->to('*****@*****.**', 'CakePHP');
     $Email->cc(['*****@*****.**' => 'Mark Story', '*****@*****.**' => 'Juan Basso']);
     $Email->bcc('*****@*****.**');
     $Email->subject('Testing Message');
     $Email->attachments(['wow.txt' => ['data' => 'much wow!', 'mimetype' => 'text/plain', 'contentId' => 'important']]);
     $Email->template('test_template', 'test_layout');
     $Email->subject("L'utilisateur n'a pas pu être enregistré");
     $Email->replyTo('*****@*****.**');
     $Email->readReceipt('*****@*****.**');
     $Email->returnPath('*****@*****.**');
     $Email->domain('cakephp.org');
     $Email->theme('EuroTheme');
     $Email->emailFormat('both');
     $Email->set('var1', 1);
     $Email->set('var2', 2);
     $result = $this->QueueTransport->send($Email);
     $this->assertEquals('Email', $result['jobtype']);
     $this->assertTrue(strlen($result['data']) < 10000);
     $output = unserialize($result['data']);
     $emailReconstructed = new Email($config);
     foreach ($output['settings'] as $method => $setting) {
         call_user_func_array([$emailReconstructed, $method], (array) $setting);
     }
     $this->assertEquals($emailReconstructed->from(), $Email->from());
     $this->assertEquals($emailReconstructed->to(), $Email->to());
     $this->assertEquals($emailReconstructed->cc(), $Email->cc());
     $this->assertEquals($emailReconstructed->bcc(), $Email->bcc());
     $this->assertEquals($emailReconstructed->subject(), $Email->subject());
     $this->assertEquals($emailReconstructed->charset(), $Email->charset());
     $this->assertEquals($emailReconstructed->headerCharset(), $Email->headerCharset());
     $this->assertEquals($emailReconstructed->emailFormat(), $Email->emailFormat());
     $this->assertEquals($emailReconstructed->replyTo(), $Email->replyTo());
     $this->assertEquals($emailReconstructed->readReceipt(), $Email->readReceipt());
     $this->assertEquals($emailReconstructed->returnPath(), $Email->returnPath());
     $this->assertEquals($emailReconstructed->messageId(), $Email->messageId());
     $this->assertEquals($emailReconstructed->domain(), $Email->domain());
     $this->assertEquals($emailReconstructed->theme(), $Email->theme());
     $this->assertEquals($emailReconstructed->profile(), $Email->profile());
     $this->assertEquals($emailReconstructed->viewVars(), $Email->viewVars());
     $this->assertEquals($emailReconstructed->template(), $Email->template());
     //for now cannot be done 'data' is base64_encode on set but not decoded when get from $email
     //$this->assertEquals($emailReconstructed->attachments(),$Email->attachments());
     //debug($output);
     //$this->assertEquals($Email, $output['settings']);
 }
 /**
  * TestSend method
  *
  * @return void
  */
 public function testSendWithEmail()
 {
     $Email = new Email();
     $Email->from('*****@*****.**', 'CakePHP Test');
     $Email->to('*****@*****.**', 'CakePHP');
     $Email->cc(['*****@*****.**' => 'Mark Story', '*****@*****.**' => 'Juan Basso']);
     $Email->bcc('*****@*****.**');
     $Email->subject('Testing Message');
     $Email->transport('queue');
     $config = $Email->config('default');
     $this->QueueTransport->config($config);
     $result = $this->QueueTransport->send($Email);
     $this->assertEquals('Email', $result['job_type']);
     $this->assertTrue(strlen($result['data']) < 10000);
     $output = json_decode($result['data'], true);
     $this->assertEquals('Testing Message', $output['settings']['_subject']);
 }
Ejemplo n.º 16
0
    protected function _execute(array $data)
    {
        $send_to = '*****@*****.**';
        if (preg_match('dev', Router::url('/', true))) {
            $send_to = '*****@*****.**';
        } else {
            $send_to = '*****@*****.**';
        }
        // Send an email.
        $message = 'Site: ' . Router::url('/', true) . '
User: '******'name'] . '
Email: ' . $data['email'] . '

{START}' . $data['request'] . '{END}';
        $email = new Email('default');
        $email->from([$data['email'] => $data['name']])->sender($data['email'], $data['name'])->to('*****@*****.**')->subject('New Request')->send($message);
        return true;
    }
Ejemplo n.º 17
0
 /**
  * Add method
  *
  * @return mixed Redirects on successful add, renders view otherwise.
  */
 public function add()
 {
     $estate = $this->Estates->newEntity();
     if ($this->request->is('post')) {
         $estate = $this->Estates->patchEntity($estate, $this->request->data);
         if ($this->Estates->save($estate)) {
             $this->Flash->success(__('The estate has been saved.'));
             $email = new Email();
             $email->transport('default');
             $email->from(['*****@*****.**' => 'My Site'])->to('*****@*****.**')->subject('About')->send('My message');
             return $this->redirect(['action' => 'index']);
         } else {
             $this->Flash->error(__('The estate could not be saved. Please, try again.'));
         }
     }
     $this->set(compact('estate'));
     $this->set('_serialize', ['estate']);
 }
Ejemplo n.º 18
0
 /**
  * Add method
  *
  * @return void Redirects on successful add, renders view otherwise.
  */
 public function add()
 {
     $testimonial = $this->Testimonials->newEntity();
     if ($this->request->is('post')) {
         $testimonial = $this->Testimonials->patchEntity($testimonial, $this->request->data);
         $testimonial->hash = bin2hex(mcrypt_create_iv(22, MCRYPT_DEV_URANDOM));
         if ($this->Testimonials->save($testimonial)) {
             $email = new Email('default');
             $email->from(['*****@*****.**' => 'Review service'])->to($testimonial->client_email)->subject('Please write review')->send('Dear ' . $testimonial->client_name . '\\r\\nPlease visit http://itaxe.pl/clients/testimonial/testimonials/edit/' . $testimonial->hash . ' to leave short review about transaction');
             $this->Flash->success(__('The testimonial has been saved and email to client sent.'));
             return $this->redirect(['action' => 'index']);
         } else {
             $this->Flash->error(__('The testimonial could not be saved. Please, try again.'));
         }
     }
     $businesses = $this->Testimonials->Businesses->find('list', ['limit' => 200]);
     $this->set(compact('testimonial', 'businesses'));
     $this->set('_serialize', ['testimonial']);
 }
 /**
  * Send mail
  *
  * @param \Cake\Mailer\Email $email Email
  * @return array
  */
 public function send(Email $email)
 {
     if (!empty($this->_config['queue'])) {
         $this->_config = $this->_config['queue'] + $this->_config;
         $email->config((array) $this->_config['queue'] + ['queue' => []]);
         unset($this->_config['queue']);
     }
     $settings = ['from' => [$email->from()], 'to' => [$email->to()], 'cc' => [$email->cc()], 'bcc' => [$email->bcc()], 'charset' => [$email->charset()], 'replyTo' => [$email->replyTo()], 'readReceipt' => [$email->readReceipt()], 'returnPath' => [$email->returnPath()], 'messageId' => [$email->messageId()], 'domain' => [$email->domain()], 'getHeaders' => [$email->getHeaders()], 'headerCharset' => [$email->headerCharset()], 'theme' => [$email->theme()], 'profile' => [$email->profile()], 'emailFormat' => [$email->emailFormat()], 'subject' => method_exists($email, 'getOriginalSubject') ? [$email->getOriginalSubject()] : [$email->subject()], 'transport' => [$this->_config['transport']], 'attachments' => [$email->attachments()], 'template' => $email->template(), 'viewVars' => [$email->viewVars()]];
     foreach ($settings as $setting => $value) {
         if (array_key_exists(0, $value) && ($value[0] === null || $value[0] === [])) {
             unset($settings[$setting]);
         }
     }
     $QueuedJobs = $this->getQueuedJobsModel();
     $result = $QueuedJobs->createJob('Email', ['settings' => $settings]);
     $result['headers'] = '';
     $result['message'] = '';
     return $result;
 }
 /**
  * Send mail via SparkPost REST API
  *
  * @param \Cake\Mailer\Email $email Email message
  * @return array
  */
 public function send(Email $email)
 {
     // Load SparkPost configuration settings
     $apiKey = $this->config('apiKey');
     // Set up HTTP request adapter
     $adapter = new CakeHttpAdapter(new Client());
     // Create SparkPost API accessor
     $sparkpost = new SparkPost($adapter, ['key' => $apiKey]);
     // Pre-process CakePHP email object fields
     $from = (array) $email->from();
     $sender = sprintf('%s <%s>', mb_encode_mimeheader(array_values($from)[0]), array_keys($from)[0]);
     $to = (array) $email->to();
     $recipients = [['address' => ['name' => mb_encode_mimeheader(array_values($to)[0]), 'email' => array_keys($to)[0]]]];
     // Build message to send
     $message = ['from' => $sender, 'html' => empty($email->message('html')) ? $email->message('text') : $email->message('html'), 'text' => $email->message('text'), 'subject' => mb_decode_mimeheader($email->subject()), 'recipients' => $recipients];
     // Send message
     try {
         $sparkpost->transmission->send($message);
     } catch (APIResponseException $e) {
         // TODO: Determine if BRE is the best exception type
         throw new BadRequestException(sprintf('SparkPost API error %d (%d): %s (%s)', $e->getAPICode(), $e->getCode(), ucfirst($e->getAPIMessage()), $e->getAPIDescription()));
     }
 }
Ejemplo n.º 21
0
 public function certificadoParticipante()
 {
     $connection = ConnectionManager::get('default');
     $participantes = $connection->execute('SELECT users.id, users.nome, users.email FROM users WHERE users.credenciado=1 AND users.rec_certificado=0 ORDER BY users.id ASC LIMIT 100')->fetchAll('assoc');
     foreach ($participantes as $user) {
         $this->set(compact('user'));
         $CakePdf = new \CakePdf\Pdf\CakePdf();
         $CakePdf->orientation('landscape');
         $CakePdf->template('certificado', 'certificado_participante');
         $CakePdf->viewVars($this->viewVars);
         $pdf = $CakePdf->output();
         // 			enviar e-mail
         $email = new Email('default');
         $email->from(['*****@*****.**' => 'EnTec 2016'])->emailFormat('html')->to(strtolower($user['email']))->template('default', 'certificado_participante')->subject('[EnTec 2016] Certificado de Participante')->viewVars(['nome' => $user['nome']])->attachments(array('ENTEC16_certificado_participante.pdf' => array('data' => $pdf, 'mimetype' => 'application/pdf')))->send();
         $this->Users->updateAll(['rec_certificado' => 1], ['id' => $user['id']]);
         // 				$pdf = $CakePdf->write(APP . 'files' . DS . 'minicurso'.$part['user_id'].'_'.rand(1,5000).'.pdf');
     }
     $this->Flash->default(__('Foram enviados ' . count($participantes) . ' certificados'));
     return $this->redirect($this->referer());
 }
Ejemplo n.º 22
0
 protected function _execute(array $data)
 {
     $email = new Email('oneeurohost');
     $email->from([$data['email'] => $data['name']])->to('*****@*****.**')->subject('Garage-dobbelaere.be: ' . $data['subject'])->send($data['body']);
     return true;
 }
Ejemplo n.º 23
0
 /**
  * Prepares the `from` email address.
  *
  * @param \Cake\Mailer\Email $email Email instance
  * @return array
  */
 protected function _prepareFromAddress($email)
 {
     $from = $email->returnPath();
     if (empty($from)) {
         $from = $email->from();
     }
     return $from;
 }
Ejemplo n.º 24
0
 public function sendMail()
 {
     $this->autoRender = FALSE;
     $data = $this->request->data;
     $from = ['*****@*****.**' => $data['fname'] . ' ' . $data['lname']];
     $to = '*****@*****.**';
     $subject = "QuickServe sales inquiry";
     $content = "";
     $content .= "<table style='height: 100%; margin-left: auto; margin-right: auto;' width='677'><tbody>" . "<tr><td colspan='2'><h1 style='text-align: center;'><span style='color: #ff0000;'><strong>Sales Inquiry</strong></span></h1></td></tr>" . "<tr><td style='text-align: justify;' width='30px'><h2 style='padding-left: 30px;'><strong>Name:</strong></h2></td>" . "<td>&nbsp;<span style='font-size: 12pt;'>" . $data['fname'] . " " . $data['lname'] . "</span></td></tr>" . "<tr><td style='text-align: justify;'><h2 style='padding-left: 30px;'><strong>Email:</strong></h2></td>" . "<td><span style='font-size: 12pt;'>&nbsp;" . $data['email'] . "</span></td></tr>" . "<tr><td style='text-align: justify;'><h2 style='padding-left: 30px;'><strong>Phone:</strong></h2></td>" . "<td>&nbsp;<span style='font-size: 12pt;'>" . $data['phone'] . "</span></td></tr>" . "<tr><td style='text-align: justify;'><h2 style='text-align: justify; padding-left: 30px;'><strong>Restaurant:</strong></h2></td>" . "<td><span style='font-size: 12pt;'>&nbsp;" . $data['restaurant'] . "</span></td></tr>" . "<tr><td style='text-align: justify;'><h2 style='text-align: justify; padding-left: 30px;'><strong>Comment</strong></h2></td>" . "<td style='word-break: break-all;'><p style='text-align: justify;'><span style='font-size: 12pt;'>" . $data['msg'] . "</span></p></td></tr>" . "</tbody></table>";
     try {
         $mailer = new Email();
         $mailer->transport('quickserve');
         $mailer->template('', 'default');
         $headers = ['Content-Type:text/HTML'];
         $result = $mailer->from($from)->emailFormat('html')->to($to)->template('default')->subject($subject)->send($content);
         if ($result) {
             $this->response->body(true);
         } else {
             $this->response->body(false);
         }
     } catch (Exception $e) {
         $this->response->body(false);
     }
 }
Ejemplo n.º 25
0
 function send_email($sendto = "", $from = "", $send = "", $subject = "")
 {
     $email = new Email('mailjet');
     $email->from([$from])->to($sendto)->subject($subject)->send($send);
     if ($email) {
         return "1";
     } else {
         return "0";
     }
     exit;
 }
Ejemplo n.º 26
0
 /**
  * @param mixed $charset
  * @param mixed $headerCharset
  * @return \Cake\Mailer\Email
  */
 protected function _getEmailByNewStyleCharset($charset, $headerCharset)
 {
     $email = new Email(['transport' => 'debug']);
     if (!empty($charset)) {
         $email->charset($charset);
     }
     if (!empty($headerCharset)) {
         $email->headerCharset($headerCharset);
     }
     $email->from('*****@*****.**', 'どこかの誰か');
     $email->to('*****@*****.**', 'どこかのどなたか');
     $email->cc('*****@*****.**', 'ミク');
     $email->subject('テストメール');
     $email->send('テストメールの本文');
     return $email;
 }
Ejemplo n.º 27
0
 public function sendEmailOnSubscription($data = [], $admins)
 {
     if (!$admins->isEmpty()) {
         $subject = 'Strastic : User Subscription';
         foreach ($admins as $admin) {
             $email = new Email('mandril');
             $app = new AppController();
             $email->from([$app->emailFrom => $app->appsName])->to($admin->username)->subject($subject)->template('subscription')->emailFormat('html')->set(['data' => $data])->send();
         }
     }
 }
Ejemplo n.º 28
0
 public function save()
 {
     if ($this->request->is('post')) {
         $attemptId = $this->request->data['attemptId'];
         $token = $this->request->data['token'];
         $report = $this->request->data['report'];
         $type = $this->request->data['type'];
         //'save', 'autosave', 'submit'
         $this->infolog("Report Save attempted. Attempt: " . $attemptId . "; Type: " . $type . "; Report: " . serialize($report));
         if ($attemptId && $token && $this->Reports->Attempts->checkUserAttempt($this->Auth->user('id'), $attemptId, $token)) {
             $reportQuery = $this->Reports->find('all', ['conditions' => ['Reports.attempt_id' => $attemptId, 'Reports.revision' => 0], 'order' => ['created' => 'DESC']]);
             $lastSavedReport = $reportQuery->first();
             if (!$reportQuery->isEmpty() && $lastSavedReport->type === 'submit') {
                 //Report has already been submitted, so can't save over the top
                 $this->set('status', 'Report already submitted');
                 $this->infolog("Report Save rejected - report already submitted. Attempt: " . $attemptId . "; Type: " . $type);
             } else {
                 $sectionsQuery = $this->Reports->ReportsSections->Sections->find('all');
                 $sections = $sectionsQuery->all();
                 if (!$reportQuery->isEmpty()) {
                     //Change old version to a revision
                     $oldReportData = $lastSavedReport;
                     $oldReportData->revision = true;
                 } else {
                     $oldReportData = null;
                 }
                 $reportData = $this->Reports->newEntity();
                 $reportData->attempt_id = $attemptId;
                 $reportData->revision = false;
                 $reportData->type = $type;
                 $reportData->serialised = serialize($report);
                 $sectionsData = [];
                 foreach ($sections as $section) {
                     $sectionData = $this->Reports->ReportsSections->newEntity();
                     $sectionData->section_id = $section->id;
                     $sectionData->text = $report[$section->id];
                     $sectionsData[] = $sectionData;
                 }
                 $reportData->reports_sections = $sectionsData;
                 $connection = ConnectionManager::get('default');
                 $connection->transactional(function () use($reportData, $oldReportData, $attemptId, $type) {
                     if (!$this->Reports->save($reportData)) {
                         $this->set('status', 'failed');
                         $this->infolog("Report Save failed (new report). Attempt: " . $attemptId . "; Type: " . $type);
                         return false;
                     }
                     if (!is_null($oldReportData) && !$this->Reports->save($oldReportData)) {
                         $this->set('status', 'failed');
                         $this->infolog("Report Save failed (old report). Attempt: " . $attemptId . "; Type: " . $type);
                         return false;
                     }
                     //If this is a submission, and the user has already been marked, then this is a resubmission, so notify the marker
                     if ($type === 'submit') {
                         $userId = $this->Auth->user('id');
                         $session = $this->request->session();
                         //Set Session to variable
                         $ltiResourceId = $session->read('LtiResource.id');
                         $markQuery = $this->Reports->Attempts->LtiResources->Marks->find('all', ['conditions' => ['Marks.lti_resource_id' => $ltiResourceId, 'Marks.lti_user_id' => $userId, 'Marks.mark' === 'Fail', 'Marks.revision' => 0], 'order' => ['Marks.modified' => 'DESC'], 'contain' => ['Marker', 'LtiUsers']]);
                         if (!$markQuery->isEmpty()) {
                             $mark = $markQuery->first();
                             $message = '<div style="font-family: Verdana, Tahoma, sans-serif; font-size: 12px;"><p>Dear ' . $mark->marker->lti_lis_person_name_given . ',</p><p>' . $mark->lti_user->lti_lis_person_name_full . ' (' . $mark->lti_user->lti_displayid . '), whose Viral Outbreak iCase report you marked as a fail, has resubmitted their report for remarking.</p><p>Please <a href="https://weblearn.ox.ac.uk/access/basiclti/site/8dd25ab4-a0ca-4e16-0073-d2a9667b58ce/content:122">go to the iCase</a> (<a href="https://weblearn.ox.ac.uk/access/basiclti/site/8dd25ab4-a0ca-4e16-0073-d2a9667b58ce/content:122">https://weblearn.ox.ac.uk/access/basiclti/site/8dd25ab4-a0ca-4e16-0073-d2a9667b58ce/content:122</a>) and remark this student. You can filter the marks to show only those that failed to make it easier to find this student.</p><p>Thank you!</p></div>';
                             //$email = new Email(); //Use PHP Mail
                             $email = new Email('smtp');
                             //Use SMTP (dev version)
                             $email->from(['*****@*****.**' => 'Viral Outbreak iCase Admin'])->to($mark->marker->lti_lis_person_contact_email_primary)->subject('Report Resubmitted for Remarking')->emailFormat('html')->send($message);
                         }
                     }
                     $this->set('status', 'success');
                     $this->infolog("Report Save succeeded. Attempt: " . $attemptId . "; Type: " . $type);
                 });
             }
         } else {
             $this->set('status', 'denied');
             $this->infolog("Report Save denied. Attempt: " . $attemptId . "; Type: " . $type);
         }
     } else {
         $this->set('status', 'notpost');
         $this->infolog("Report Save not POST ");
     }
     $this->viewBuilder()->layout('ajax');
     $this->render('/Element/ajaxmessage');
 }
Ejemplo n.º 29
0
 /**
  * Send mail for setup user.
  *
  * @param $subject
  * @param $message
  * @param null $to
  */
 protected function _send($subject, $message, $to = null)
 {
     $mail = new Email();
     $to = $to ? $to : $this->_entity->get('email');
     $mail->from($this->fromEmail, $this->fromName)->to($to)->emailFormat('html')->template($this->_tplMessage)->subject($subject)->send($message);
 }
Ejemplo n.º 30
0
 /**
  * testGetLastResponse method
  *
  * @return void
  */
 public function testGetLastResponse()
 {
     $this->assertEmpty($this->SmtpTransport->getLastResponse());
     $this->socket->expects($this->any())->method('connect')->will($this->returnValue(true));
     $this->socket->expects($this->at(0))->method('read')->will($this->returnValue(false));
     $this->socket->expects($this->at(1))->method('read')->will($this->returnValue("220 Welcome message\r\n"));
     $this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n");
     $this->socket->expects($this->at(3))->method('read')->will($this->returnValue(false));
     $this->socket->expects($this->at(4))->method('read')->will($this->returnValue("250-PIPELINING\r\n"));
     $this->socket->expects($this->at(5))->method('read')->will($this->returnValue("250-SIZE 102400000\r\n"));
     $this->socket->expects($this->at(6))->method('read')->will($this->returnValue("250-VRFY\r\n"));
     $this->socket->expects($this->at(7))->method('read')->will($this->returnValue("250-ETRN\r\n"));
     $this->socket->expects($this->at(8))->method('read')->will($this->returnValue("250-STARTTLS\r\n"));
     $this->socket->expects($this->at(9))->method('read')->will($this->returnValue("250-AUTH PLAIN LOGIN\r\n"));
     $this->socket->expects($this->at(10))->method('read')->will($this->returnValue("250-AUTH=PLAIN LOGIN\r\n"));
     $this->socket->expects($this->at(11))->method('read')->will($this->returnValue("250-ENHANCEDSTATUSCODES\r\n"));
     $this->socket->expects($this->at(12))->method('read')->will($this->returnValue("250-8BITMIME\r\n"));
     $this->socket->expects($this->at(13))->method('read')->will($this->returnValue("250 DSN\r\n"));
     $this->SmtpTransport->connect();
     $expected = [['code' => '250', 'message' => 'PIPELINING'], ['code' => '250', 'message' => 'SIZE 102400000'], ['code' => '250', 'message' => 'VRFY'], ['code' => '250', 'message' => 'ETRN'], ['code' => '250', 'message' => 'STARTTLS'], ['code' => '250', 'message' => 'AUTH PLAIN LOGIN'], ['code' => '250', 'message' => 'AUTH=PLAIN LOGIN'], ['code' => '250', 'message' => 'ENHANCEDSTATUSCODES'], ['code' => '250', 'message' => '8BITMIME'], ['code' => '250', 'message' => 'DSN']];
     $result = $this->SmtpTransport->getLastResponse();
     $this->assertEquals($expected, $result);
     $email = new Email();
     $email->from('*****@*****.**', 'CakePHP Test');
     $email->to('*****@*****.**', 'CakePHP');
     $this->socket->expects($this->at(0))->method('write')->with("MAIL FROM:<*****@*****.**>\r\n");
     $this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
     $this->socket->expects($this->at(2))->method('read')->will($this->returnValue("250 OK\r\n"));
     $this->socket->expects($this->at(3))->method('write')->with("RCPT TO:<*****@*****.**>\r\n");
     $this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false));
     $this->socket->expects($this->at(5))->method('read')->will($this->returnValue("250 OK\r\n"));
     $this->SmtpTransport->sendRcpt($email);
     $expected = [['code' => '250', 'message' => 'OK']];
     $result = $this->SmtpTransport->getLastResponse();
     $this->assertEquals($expected, $result);
 }