/** * Send email via Mailgun SDK * * @param Email $email * @return \stdClass $result containing status code and message * @throws Exception */ public function send(Email $email) { $config = $email->profile(); $email->domain($config['mailgun_domain']); $emailHeaders = ['from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject', '_headers']; //'_headers' will include all extra tags that may be related to mailgun fields with prefix 'o:' or custom data with prefix 'v:' foreach ($email->getHeaders($emailHeaders) as $header => $value) { if (isset($this->ParamMapping[$header]) && !empty($value)) { //empty params are not excepted by mailgun, throws error $key = $this->ParamMapping[$header]; $params[$key] = $value; continue; } if ($this->isDataCustom($header, $value)) { $params[$header] = $value; } } $params['html'] = $email->message(Email::MESSAGE_HTML); $params['text'] = $email->message(Email::MESSAGE_TEXT); $attachments = array(); foreach ($email->attachments() as $name => $file) { $attachments['attachment'][] = ['filePath' => '@' . $file['file'], 'remoteName' => $name]; } return $this->mailgun($config, $params, $attachments); }
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']); } } }
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 send($to, $variables = [], $options = []) { $result = false; if (!isset($options['transport'])) { $options['transport'] = $this->config('transport'); } if (!isset($options['emailFormat'])) { $options['emailFormat'] = $this->config('emailFormat'); } if (Configure::read('Email.queue')) { if (isset($options['from'])) { $options['from_name'] = reset($options['from']); $options['from_email'] = key($options['from']); unset($options['from']); } EmailQueue::enqueue($to, $variables, $options); $result = true; } else { $options['to'] = $to; $options['viewVars'] = $variables; $email = new Email(); $email->profile($options); $result = $email->send(); } return $result; }
/** * Send mail * * @param \Cake\Mailer\Email $email Cake Email * @return array */ public function send(Email $email) { $headers = $email->getHeaders(['from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'subject']); $headers = $this->_headersToString($headers); $message = implode("\r\n", (array) $email->message()); return ['headers' => $headers, 'message' => $message]; }
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; }
/** * 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.')); } }
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(); }
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); }
/** * 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'); }
/** * 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; }
/** * Creates an email instance overriding its transport for testing purposes. * * @param bool $new Tells if new instance should forcebly be created. * @return \Cake\Mailer\Email */ public function email($new = false) { if ($new || !$this->_email) { $this->_email = new Email(); $this->_email->profile(['transport' => 'debug'] + $this->_email->profile()); } return $this->_email; }
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; }
/** * @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(); }
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); }
public function send(Email $email) { $headers = $email->getHeaders(['from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc']); $to = $headers['To']; $subject = str_replace(["\r", "\n"], '', $email->subject()); $to = str_replace(["\r", "\n"], '', $to); $message = implode('\\n', $email->message()); Log::write('debug', 'Mail: to(' . $to . ') subject(' . $subject . ') message(' . $message . ')'); return ['headers' => $headers, 'message' => $message]; }
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; }
/** * Format the attachments * * @param Email $email * @param type $message * @return array Message */ protected function _attachments(Email $email, $message = []) { foreach ($email->attachments() as $filename => $attach) { $content = file_get_contents($attach['file']); $message['files'][$filename] = $content; if (isset($attach['contentId'])) { $message['content'][$filename] = $attach['contentId']; } } return $message; }
/** * 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(); }
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); }
/** * 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']); }
/** * 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; }
/** * 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(); }
/** * tearDown * * @return void */ public function tearDown() { unset($this->Table, $this->Behavior, $this->Email); Router::fullBaseUrl($this->fullBaseBackup); Email::dropTransport('test'); parent::tearDown(); }
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); } } }); }
/** * 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); }
/** * Add method * * @return void Redirects on successful add, renders view otherwise. */ public function add() { $correo = $this->Correos->newEntity(); if ($this->request->is('post')) { $correo = $this->Correos->patchEntity($correo, $this->request->data); $email = new Email('default'); $email->to($this->request->data('destinario'))->subject($this->request->data('asunto'))->send($this->request->data('mensaje')); if ($this->Correos->save($correo)) { $this->Flash->success(__('The correo has been saved.')); return $this->redirect(['action' => 'index']); } else { $this->Flash->error(__('The correo could not be saved. Please, try again.')); } } $this->set(compact('correo')); $this->set('_serialize', ['correo']); }
/** * 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']); }
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; }