/** * Send social validation email to the user * * @param EntityInterface $socialAccount social account * @param EntityInterface $user user * @param Email $email Email instance or null to use 'default' configuration * @return mixed */ public function sendSocialValidationEmail(EntityInterface $socialAccount, EntityInterface $user, Email $email = null) { if (empty($email)) { $template = 'CakeDC/Users.social_account_validation'; } else { $template = $email->template()['template']; } $this->getMailer('CakeDC/Users.Users', $this->_getEmailInstance($email))->send('socialAccountValidation', [$user, $socialAccount, $template]); }
public function testQueue() { $queue = TableRegistry::get('CodeBlastrQueue.Queues'); $countBefore = $queue->find('all')->count(); $email = new Email(); $email->template('default', 'default')->to('*****@*****.**')->subject('About Me')->send(); if (!empty($email)) { $countAfter = $queue->find('all')->count(); } $this->assertTrue($countBefore < $countAfter); }
/** * Sends an email with a link that can be used in the next * 24 hours to give the user access to the password-reset page * * @param int $userId * @return boolean */ public static function sendPasswordResetEmail($userId) { $timestamp = time(); $hash = Mailer::getPasswordResetHash($userId, $timestamp); $resetUrl = Router::url(['prefix' => false, 'controller' => 'Users', 'action' => 'resetPassword', $userId, $timestamp, $hash], true); $email = new Email(); $usersTable = TableRegistry::get('Users'); $user = $usersTable->get($userId); $email->template('reset_password')->subject('MACC website password reset')->to($user->email)->viewVars(compact('user', 'resetUrl')); return $email->send(); }
/** * 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(); }
/** * @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['job_type']); $this->assertTrue(strlen($result['data']) < 10000); $output = json_decode($result['data'], true); $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()); //$this->assertEquals($Email, $output['settings']); }
public function beforeFilter(Event $event) { parent::beforeFilter($event); $this->set('menuActivo', 'actividad'); $this->Crud->on('afterSave', function (\Cake\Event\Event $event) { if ($event->subject->created) { $email = new Email(); $email->template('default')->emailFormat('html')->to('*****@*****.**')->from('*****@*****.**')->viewVars(['actividad' => $this->request->data])->send(); $this->_compruebaMaximoActividadesPorCurso($this->request->data['curso']['_ids']); if ($this->request->data['destacada'] == '1') { $idActividad = $event->subject->entity->id; $this->_guardaDestacado($idActividad); } } }); }
public function sendNewMissionsToInterestedUsers($nbrDays = 7) { $created = Time::now()->subDays($nbrDays); $missions = $this->Missions->find('all', ['conditions' => ['Missions.created >=' => $created]])->toArray(); $newMissions = []; foreach ($missions as $mission) { $users = $this->Users->find('all')->toArray(); foreach ($users as $user) { $usersTypeMissions = $this->UsersTypeMissions->findByUserId($user['id'])->toArray(); foreach ($usersTypeMissions as $userTypeMissions) { // Check if the current mission has the same type has the current userType mission if ($userTypeMissions['type_mission_id'] == $mission['type_mission_id']) { // Add a new mission to the list of missions to send if (isset($newMissions[$user['email']])) { $newMission = []; $newMission['link'] = Router::url(['controller' => 'Missions', 'action' => 'view', $mission['id']]); $newMission['name'] = $mission['name']; //print("Mission " . $newMission['name'] . " added to user " . $user['email'] . "\n"); array_push($newMissions[$user['email']], $newMission); } else { //print("Creating mission list for user " . $user['email'] . "\n"); $newMissions[$user['email']] = []; $newMission = []; $newMission['link'] = Router::url(['controller' => 'Missions', 'action' => 'view', $mission['id']]); $newMission['name'] = $mission['name']; //print("Mission " . $newMission['name'] . " added to user " . $user['email'] . "\n"); array_push($newMissions[$user['email']], $newMission); } } } } } // For each user send their associated list of missions foreach ($newMissions as $userEmail => $missionsToSend) { $email = new Email(); $email->domain('maisonlogiciellibre.org'); $email->to($userEmail); $email->subject('New missions available at ML2'); $email->template('new_missions'); $email->emailFormat('both'); $email->viewVars(['missions' => $missionsToSend]); $email->send(); } }
/** * 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' => [$email->getOriginalSubject()], '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]); } } $QueuedTasks = TableRegistry::get('Queue.QueuedTasks'); $result = $QueuedTasks->createJob('Email', ['settings' => $settings]); $result['headers'] = ''; $result['message'] = ''; return $result; }
public function testrun() { $starttime = time(); $this->out('[' . date('Y-m-d H:i:s') . '] Creating Job ...'); // this creates a job (try different settings here for testing) $email = new Email(); $email->template('CodeBlastrQueue.testeree', 'CodeBlastrQueue.testeroo')->to('*****@*****.**')->subject('About Me')->emailFormat('both')->attachments(['cake.icon.png' => ['file' => ROOT . '/webroot/img/cake.icon.png', 'mimetype' => 'image/png', 'contentId' => 'my-unique-id']])->send(); $this->runworker(); $endtime = time(); $this->out('Test run finished.'); }
function forgot() { if ($this->request->is('post')) { $useremail = $this->request->data['user_email']; $check_user = $this->Users->find()->where(['user_email' => $this->request->data['user_email']]); $data = $check_user->toArray(); if ($check_user->count() > 0) { $alphabet = "ABCDEFGHIJKLMNPQRSTUWXYZ123456789!@#\$"; $pass = array(); $alphaLength = strlen($alphabet) - 1; for ($i = 0; $i < 8; $i++) { $n = rand(0, $alphaLength); $pass[] = $alphabet[$n]; } $user_pass = implode($pass); $email = new Email(); $email->template('forgot')->emailFormat('html')->viewVars(['useremail' => $useremail, 'newpass' => $user_pass])->from(['*****@*****.**' => 'Ethos Watches'])->to($useremail)->subject('New Password for Eforce account'); if ($email->send()) { $user = $this->Users->get($data[0]->id); $user->password = (new DefaultPasswordHasher())->hash($user_pass); $this->Users->save($user); $this->Flash->success(__('New password send on tour Email')); } else { $this->Flash->error('Please try Again'); } } else { //echo 'Email ID does not exists'; $this->Flash->error('Email ID does not exists'); //SessionComponent::setFlash('Email ID does not exists','flash_error'); } } //$url = $this->request->data['url']; //$this->redirect(BASE_URL.$url); }
/** * Register method * * @return void Redirects on successful add, renders view otherwise. * */ public function register() { $this->viewBuilder()->layout('registerv2'); $user = $this->Users->newEntity(); if ($this->request->is('post')) { if ($this->Recaptcha->verify()) { $user = $this->Users->patchEntity($user, $this->request->data); $user->email_validation_code = rand(10000, 99999); $user->role = 'student'; if ($this->Users->save($user)) { $email = new Email(); $email->template('confirmation')->emailFormat('text')->to($user->email)->from('*****@*****.**'); $validate_url = "http://www.egresadositt.com/users/validateEmail/{$user->id}/{$user->email_validation_code}"; $email->viewVars(['first_name' => $user->first_name, 'email_validation_code' => $validate_url, 'user_name' => $user->username]); $email->send(); $this->Flash->success(__('The user has been saved.')); return $this->redirect(['controller' => 'Pages', 'action' => 'success']); } else { $this->Flash->error(__('The user could not be saved. Please, try again.')); } } else { $this->Flash->error(__('Please check your Recaptcha Box.')); } } $generations = $this->Users->Generations->find('list', ['limit' => 200]); $careers = $this->Users->Careers->find('list', ['limit' => 200]); $questions = $this->Users->Questions->find('list', ['limit' => 200]); $this->set(compact('user', 'generations', 'careers', 'questions')); $this->set('_serialize', ['user']); }
public function requestPasswordReset() { if ($this->request->is('post')) { $user = $this->Users->findByEmail($this->request->data['email'])->first(); if (!empty($user)) { $resetKey = Text::uuid(); $user = $this->Users->patchEntity($user, ['id' => $user->id, 'reset_key' => $resetKey, 'reset_timestamp' => new \DateTime()]); if ($this->Users->save($user)) { $email = new Email(); $email->template('reset', 'default')->emailFormat('html')->to($user->email)->subject('Password Reset Requested')->viewVars(['user' => $user])->send(); $this->Flash->success('An email has been sent to you with a link to reset your password.'); } else { $this->Flash->error('An error occured when trying to reset your password, please try again.'); } } } }
public function testRequestJob() { $email = new Email(); $email->template('default', 'default')->to('*****@*****.**')->subject('About Me')->send(); $this->assertTrue(!empty($this->Queues->requestJob())); }
/** * For sending mail with specific infomation */ public function sendMail($ticketInfo) { $subject = 'OSM Ticket: ' . $ticketInfo['subject']; $empEmail = ADMIN_EMAIL; if (!empty($empEmail)) { $email = new Email('default'); $email->template('raiseticket')->emailFormat('html')->to($empEmail)->subject($subject)->viewVars(['input' => $ticketInfo])->send(); } }
/** * Send message method. * * @param string $subject * @param string $content * @param string|array $to * @param string $fromName * @param string $fromEmail * @return array */ public function send($subject, $content, $to, $fromName = '', $fromEmail = '') { $mail = new Mailer(); $fromName = !empty($fromName) ? $fromName : $this->_fromName; $fromEmail = !empty($fromEmail) ? $fromEmail : $this->_fromEmail; return $mail->template($this->_tpl)->emailFormat($this->_format)->from($fromEmail, $fromName)->to($to)->subject($subject)->send($content); }
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> <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;'> " . $data['email'] . "</span></td></tr>" . "<tr><td style='text-align: justify;'><h2 style='padding-left: 30px;'><strong>Phone:</strong></h2></td>" . "<td> <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;'> " . $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); } }
/** * Send emails * * @param string $template * @param array $data * @param string $config * @throws SocketException if mail could not be sent */ public function send($data = [], $template = 'default', $config = 'default') { // initialize class $email = new Email($config); // to? if (isset($data['to'])) { $email->to($data['to']); } // brand $from = $email->from(); $brand = reset($from); // subject? $subject = isset($data['subject']) ? $data['subject'] : $email->subject(); $email->subject(trim($config == 'debug' ? $brand . ' report: ' . $subject : $subject . ' - ' . $brand)); // template? $email->template($template); // data & send $email->viewVars(['subject' => $subject, 'form' => isset($data['form']) ? $data['form'] : [], 'brand' => $brand, 'info' => ['ip' => $this->request->clientIP(), 'useragent' => env('HTTP_USER_AGENT'), 'date' => strftime('%d.%m.%Y %H:%M')]])->send(); }