public function gmail() { $email = new Email('gmail-profile'); $email->emailFormat('html')->template('compra', 'default')->viewVars(['nombres' => 'Erick Benites', 'producto' => 'CakePHPCookbook'])->to('*****@*****.**')->subject('Correo desde CakePHP 3 con Gmail')->attachments(['CakePHPCookbook.pdf' => WWW_ROOT . 'CakePHPCookbook.pdf', 'photo.png' => ['file' => WWW_ROOT . 'img/logo.png', 'mimetype' => 'image/png', 'contentId' => 'logo-id']])->send("Contenido adicional ... \n ..."); echo 'Correo enviado'; $this->autoRender = false; }
public function registration() { if ($this->request->is('post')) { $first_name = $this->request->data['first_name']; $last_name = $this->request->data['last_name']; $bussiness_name = $this->request->data['bussiness_name']; $email = $this->request->data['email']; $mobile = $this->request->data['mobile']; $msg = '<h3>Registration Successfull. Following is the user detail.</h3><br><br><br>'; $msg .= '<strong>First Name : </strong>' . $first_name . '<br>'; $msg .= '<strong>Last Name : </strong>' . $last_name . '<br>'; $msg .= '<strong>Bussiness Name : </strong>' . $bussiness_name . '<br>'; $msg .= '<strong>Email : </strong>' . $email . '<br>'; $msg .= '<strong>Mobile : </strong>' . $mobile . '<br>'; $email = new Email('default'); $res = $email->emailFormat('html')->from(['*****@*****.**' => 'Terraapp User'])->to('*****@*****.**')->subject('Registration')->send($msg); if (!empty($res)) { $data = '<div class="showSuccess">Registration Successfull.</div>'; echo json_encode(array('response' => 1, 'data' => $data)); } else { $data = '<div class="showSuccess">Error in registration.</div>'; echo json_encode(array('response' => 0, 'data' => $data)); } exit; } }
/** * Get or initialize the email instance. Used for mocking. * * @param Email $email if email provided, we'll use the instance instead of creating a new one * @return Email */ protected function _getEmailInstance(Email $email = null) { if ($email === null) { $email = new Email('default'); $email->emailFormat('both'); } return $email; }
/** * send email * * @access public * @author sakuragawa */ public function send($config, $code, $errorType, $description, $file, $line, $context) { $subject = $this->subject($config, $errorType, $description); $body = $this->body($config, $description, $file, $file, $context); $format = 'text'; if ($config['mail']['html'] === true) { $format = 'html'; } $email = new Email('error'); $email->emailFormat($format)->subject($subject)->send($body); }
/** * View single order * @param $id */ public function email($id) { $row = $this->Orders->findById($id)->contain(["Users", "Statuses", "Operations", "Accessories", "Images", "Files"])->first(); if (!$row) { throw new InternalErrorException("Chyba pri nacitani objednavky", 500); } $email = new Email(); $email->emailFormat('html')->template('order_client')->transport('default')->viewVars(['message' => $this->request->data('message'), 'row' => $row, 'name' => $row['user']['name'], 'username' => $row['user']['username']])->to($this->request->data('email'))->from($row['user']['username'])->subject($this->request->data('subject') . ' - taznezariadenia.sk')->send(); $this->set('row', $row); $this->set('_serialize', ['row']); }
/** * 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']); }
/** * Send an activation link to user email * @param $user */ public function _sendActivationEmail(Entity $user, $url = '/register/active/') { $ActivationKeys = TableRegistry::get('Users.ActivationKeys'); $activationKeyEntity = $ActivationKeys->newEntity(); $activationKeyEntity->user_id = $user->id; do { $activationKeyEntity->activation_key = Text::uuid(); } while (!$ActivationKeys->save($activationKeyEntity)); //send email with activation key $activationUrl = Router::url($url . $activationKeyEntity->activation_key, true); $email = new Email('default'); // $email->transport(); $email->emailFormat('html'); $email->viewVars(compact('activationUrl')); $email->helpers(['Html']); $email->to($user->username); return $email; }
public function comprar() { if ($this->request->is('post')) { $carrito = $this->request->session()->read('carrito'); if (!$carrito) { $carrito = array(); } $nombres = $this->request->data('nombres'); $correo = $this->request->data('correo'); $email = new Email('default'); // Seleccionar el profile a usar $email->emailFormat('html')->template('pedido')->viewVars(['nombres' => $nombres, 'carrito' => $carrito])->from(['*****@*****.**' => 'Tienda Online'])->to($correo)->cc('*****@*****.**')->subject('Agradecemos su pedido')->send(); // Eliminar la sesion y los datos del carrito $this->request->session()->destroy(); $this->Flash->success('Su pedido está siendo procesado. ¡Muchas gracias!'); $this->redirect(['action' => 'index']); } }
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' => 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; }
public function index($locale = null) { $this->localeSite($locale); $commentsTable = TableRegistry::get('userComments'); $comments = $commentsTable->find()->select(['first_name', 'picture', 'comment'])->where(['approved = 1'])->toArray(); if ($this->request->is('post')) { $message = ""; foreach ($this->request->data as $key => $value) { if (!empty($value)) { $message .= $key . ": " . $value . "<br />"; } } $email = new Email('primegroupbr'); if ($email->emailFormat('html')->to('*****@*****.**')->subject('Contato')->send($message)) { $this->Flash->success('Your contact has been sent.'); } } $this->set('comments', $comments); }
public function sendExtNotify($from, $to, $template = "default", $subject = "", $content) { $this->Users = TableRegistry::get('Users'); // Don't Sent Message From Self to Self if ($from == $to) { return false; } $toUser = $this->Users->findById($to)->first(); $fromUser = $this->Users->findById($from)->first(); // Unable to load either user. This is bad. if (empty($toUser)) { return false; } if (empty($fromUser)) { return false; } // Don't send to a non-notified user if (!$toUser->is_notified) { return false; } $email = new Email('default'); $email->emailFormat('both')->template($template)->to($toUser->username)->cc($fromUser->username)->subject($subject)->viewVars($content)->send(); return true; }
/** * Save new user * */ public function forgot() { $username = $this->request->data('username'); $user = $this->Users->find()->where(['username' => $this->request->data('username')])->first(); if (!$user) { $this->response->header('HTTP/1.1', '500 Internal Server Error'); $err[] = "Užívateľ nebol najdený"; $this->set('errors', $err); $this->set('_serialize', ['errors']); } else { $user->new_pass = $this->generateRandomString(6); $this->Users->save($user); $email = new Email(); $email->emailFormat('html')->template('forgot')->transport('default')->viewVars(['hash' => sha1($user->new_pass), 'password' => $user->new_pass])->to($username)->from($username)->subject('Reset hesla - taznezariadenia.sk')->send(); $this->set('user', $user->new_pass); $this->set('_serialize', ['user']); } }
function forgot_password() { if (!is_null($this->Auth->user('id'))) { $this->Flash->error(__('You have not forgotten your password, you are logged in.')); return $this->redirect('/'); } if ($this->request->is(['post']) && !empty($this->request->data(['username']))) { $userReset = $this->Users->findByUsername($this->request->data['username'])->first(); if (empty($userReset)) { $this->Flash->error(__('Password reset instructions sent. You have 24 hours to complete this request.')); return $this->redirect('/'); } else { $userReset = $this->__genPassToken($userReset); if ($this->Users->save($userReset)) { $email = new Email('default'); $email->emailFormat('both')->template('reset')->to($userReset->username)->subject('Password Reset Requested')->viewVars(['username' => $userReset->username, 'ip' => $_SERVER['REMOTE_ADDR'], 'hash' => $userReset->reset_hash, 'expire' => $userReset->reset_hash_time, 'fullURL' => "http://" . $_SERVER['HTTP_HOST'] . "/users/reset_password/"])->send(); $this->Flash->error(__('Password reset instructions sent. You have 24 hours to complete this request.')); return $this->redirect('/'); } } } }