/** * Test configuration * * @return void */ public function testConfig() { $Email = new Email(); $Email->transport('queue'); $Email->config('default'); $res = $Email->transport()->config(); //debug($res); //$this->assertTrue(isset($res['queue'])); }
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(); }
/** * Test required fields * * @return void */ public function testMissingRequiredFields() { $this->setExpectedException('BadMethodCallException'); $this->SparkPostTransport->config($this->validConfig); $email = new Email(); $email->transport($this->SparkPostTransport); $email->to('*****@*****.**')->subject('This is test subject')->emailFormat('text')->send('Testing Maingun'); }
/** * 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(); }
/** * Send mail * * @param 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']); } $transport = $this->_config['transport']; $email->transport($transport); $QueuedTasks = TableRegistry::get('Queue.QueuedTasks'); $result = $QueuedTasks->createJob('Email', ['transport' => $transport, 'settings' => $email]); $result['headers'] = ''; $result['message'] = ''; return $result; }
/** * 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']); }
/** * 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']); }
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); } }
/** * CakeEmailTest::testMockTransport() */ public function testMockTransport() { $mock = $this->getMockBuilder('\\Cake\\Mailer\\AbstractTransport')->getMock(); $config = ['from' => '*****@*****.**', 'transport' => 'default']; Email::config('default', $config); Email::configTransport('default', $mock); $em = new Email('default'); $this->assertSame($mock, $em->transport()); }
/** * Sends the user an email to confirm that the correct address has been entered * **/ private function _confirmEmail($user, $emailId) { // Generate a hash $hash = Security::hash(date('Y-m-Y-i-s') . $user['username'] . $_SERVER['REMOTE_ADDR']); // Save hash and reset time to user's record $save = $this->Users->get($user['id']); $save->reset_hash = $hash; $save->reset_time = date('Y-m-d H:i:s'); $this->Users->save($save); // Email a link including the hash to the user $to = $this->request->data['email']; $message = 'Please click on this link to confirm your email address and activate your account:' . PHP_EOL . PHP_EOL . 'http://' . $_SERVER['HTTP_HOST'] . '/users/checkEmail/' . $hash . '/' . $user['id'] . '/' . $emailId . PHP_EOL . PHP_EOL . ' -Vooderbot'; $email = new Email('default'); $email->transport('mailjet')->from(['*****@*****.**' => 'Vooders.com'])->to($to)->subject('Confirm your email address')->send($message); // Set flash and redirect $this->Flash->success(__('Thank you - we have sent you a link to confirm your email address.')); }
/** * Allow a user to request a password reset. * @return */ function forgot() { header('Content-Type: application/json'); header('Access-Control-Allow-Origin: *'); $userInfo = TableRegistry::get('Users'); $userDetails = TableRegistry::get('UserDetails'); //print_r($_REQUEST);die(); if ($this->request->query) { $user_email = $_REQUEST['email']; if (!empty($user_email)) { $users = $userInfo->find('all', ['conditions' => ['Users.email' => $user_email]]); $user = $users->first(); $user_details = $userDetails->find('all', ['conditions' => ['UserDetails.user_id' => $user->id]]); $userInfo = $user_details->first(); //echo $user->email;die; if (!$user) { $mesg['msg'] = 'Sorry, the username entered was not found.'; $mesg['response_code'] = '0'; echo json_encode($mesg); die; } else { //Time::$defaultLocale = 'es-ES'; $link = BASE_SERVER_URL . 'logins/forgotpassform'; $time = Time::now('Asia/Kolkata'); $time_new = $time->i18nFormat('yyyy-MM-dd HH:mm:ss'); $token = $user->id . "+" . $user->email . "+" . $time_new; $token_new = base64_encode($token); //$email = new Email('mailjet'); $email = new Email(); $email->transport('mailjet'); $email->viewVars(['last_name' => $userInfo->lastname]); $email->viewVars(['PASSWORD_RESET_LINK' => FORGOT_PAGE_LINK]); $email->from(['*****@*****.**' => 'My Site'])->template('forgot', 'htmlemail')->emailFormat('html')->to($user->email)->subject('Forgot Password')->send(); if ($email) { $mesg['msg'] = 'Mail send to your mail. Please check inbox.'; $mesg['response_code'] = '1'; echo json_encode($mesg); die; } } } } }
/** * Add method * * @return \Cake\Network\Response|void Redirects on successful add, renders view otherwise. */ public function register() { header('Content-Type: application/json'); header('Access-Control-Allow-Origin: *'); $email = @$_REQUEST['email']; $password = @$_REQUEST['password']; $fname = @$_REQUEST['fname']; $lname = @$_REQUEST['lname']; $blockno = @$_REQUEST['blockno']; $unitno = @$_REQUEST['unitno']; $street = @$_REQUEST['street']; $country = 'Singapore'; $postalcode = @$_REQUEST['postalcode']; $telephoneno = @$_REQUEST['telephoneno']; $fax_no = @$_REQUEST['fax_no']; $compname = @$_REQUEST['compname']; $position = @$_REQUEST['position']; $search = $email; if (empty($email)) { //EMPTY CHECK $mesg['msg'] = 'The email is empty11. Please, try again.'; $mesg['response_code'] = '0'; echo json_encode($mesg); die; } if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { //INVALID EMAIL CHECK. $mesg['msg'] = 'The email is not a valid email. Please, try again.'; $mesg['response_code'] = '0'; echo json_encode($mesg); die; } if (!preg_match('/^[a-z0-9A-Z]*$/', $password)) { $mesg['msg'] = 'The password that you have given is not valid.It should be alphanumeric.Please try again.'; $mesg['response_code'] = '0'; echo json_encode($mesg); die; } if (strlen($password) < 6) { $mesg['msg'] = 'Minimum 6 characters required for password.'; $mesg['response_code'] = '0'; echo json_encode($mesg); die; } if (!ctype_digit($telephoneno)) { $mesg['msg'] = 'Given telephone number is not a numeric.'; $mesg['response_code'] = '0'; echo json_encode($mesg); die; } if (strlen($telephoneno) > 20) { $mesg['msg'] = 'Maximum 20 characters can be used for telephone no.'; $mesg['response_code'] = '0'; echo json_encode($mesg); die; } if (!empty($fax_no)) { if (!ctype_digit($fax_no)) { $mesg['msg'] = 'Given fax number is not a numeric.'; $mesg['response_code'] = '0'; echo json_encode($mesg); die; } if (strlen($fax_no) > 20) { $mesg['msg'] = 'Maximum 20 characters can be used for fax no.'; $mesg['response_code'] = '0'; echo json_encode($mesg); die; } } $user = $this->Users->newEntity(); $getArray = array('email' => $email, 'password' => $password, 'status' => '1'); $user = $this->Users->patchEntity($user, $getArray); $query = $this->Users->find('all', ['conditions' => ['Users.email LIKE ' => '%' . $search . '%'], 'limit' => 1])->all(); $counts = $query->count(); if ($counts == '1') { //DUPLICATE MAIL CHECK $mesg['msg'] = 'The email already in use. Please, try again.'; $mesg['response_code'] = '0'; echo json_encode($mesg); die; } if ($this->Users->save($user)) { //print_r($user->id); $userAddress = TableRegistry::get('UserAddresses'); $UserDetails = TableRegistry::get('UserDetails'); $user_address = $userAddress->newEntity(); $user_address->user_id = $user->id; $user_address->street_address = $street; //$user_address->country = $country; $user_address->country = 'Singapore'; $user_address->postalcode = $postalcode; $user_address->telephone = $telephoneno; $user_address->fax_no = $fax_no; if ($userAddress->save($user_address)) { $userAddress_lastid = $user_address->id; } $User_details = $UserDetails->newEntity(); $User_details->user_id = $user->id; $User_details->firstname = $fname; $User_details->lastname = $lname; $User_details->blockno = $blockno; $User_details->unitno = $unitno; $User_details->company = $compname; $User_details->position = $position; if ($UserDetails->save($User_details)) { //$User_details_lastid = $UserDetails->getLastInsertID(); } //SEND EMAIL............................... //http://book.cakephp.org/3.0/en/core-libraries/email.html $emailer = new Email(); $emailer->transport('mailjet'); $emailer->viewVars(['last_name' => $lname]); //$emailto='*****@*****.**'; $emailto = $email; try { $res = $emailer->from(['*****@*****.**'])->template('welcome', 'fancy')->emailFormat('html')->to([$emailto => 'BLS-New User'])->subject('Membership activation')->send('test-email...'); } catch (Exception $e) { echo 'Exception : ', $e->getMessage(), "\n"; } //---------------------------------------- $mesg['msg'] = 'The user has been saved.'; $mesg['response_code'] = '1'; } else { $mesg['msg'] = 'The user could not be saved. Please, try again.'; $mesg['response_code'] = '0'; } echo json_encode($mesg); die; }
/** * Test additional headers * * @return void */ public function testAdditionalHeaders() { $this->MailgunTransport->config($this->validConfig); $email = new Email(); $email->transport($this->MailgunTransport); $result = $email->from('*****@*****.**')->to('*****@*****.**')->subject('This is test subject')->addHeaders(['o:tag' => 'testing', 'o:tracking' => 'yes'])->addHeaders(['v:custom-data' => json_encode(['foo' => 'bar'])])->send('Testing Maingun'); $this->assertEquals("test.mailgun.org/messages", $result->http_endpoint_url); }