Author: Nick Sagona, III (dev@nolainteractive.com)
Exemplo n.º 1
0
 /**
  * Send user password reset notification
  *
  * @param  mixed  $user
  * @param  string $title
  * @return void
  */
 public function sendReset($user, $title)
 {
     $host = $_SERVER['HTTP_HOST'];
     $domain = str_replace('www.', '', $host);
     $newPassword = $this->random();
     $user->password = (new Bcrypt())->create($newPassword);
     $user->save();
     $rcpt = ['name' => $user->username, 'email' => $user->email, 'domain' => $domain, 'username' => $user->username, 'password' => $newPassword, 'title' => $title];
     $mailTemplate = __DIR__ . '/../../view/mail/forgot.txt';
     // Send email verification
     $mail = new Mail($title . ' (' . $domain . ') - Password Reset', $rcpt);
     $mail->from('noreply@' . $domain);
     $mail->setText(file_get_contents($mailTemplate));
     $mail->send();
 }
Exemplo n.º 2
0
 /**
  * Send install notification email to user
  *
  * @param  \Phire\Form\User $form
  * @return void
  */
 public static function send(\Phire\Form\User $form)
 {
     $i18n = Table\Config::getI18n();
     // Get the domain
     $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
     // Set the recipient
     $rcpt = array('name' => $form->username, 'email' => $form->email1, 'url' => 'http://' . $_SERVER['HTTP_HOST'] . BASE_PATH, 'login' => 'http://' . $_SERVER['HTTP_HOST'] . BASE_PATH . APP_URI, 'domain' => $domain);
     $config = \Phire\Table\Config::findById('system_email');
     $config->value = $form->email1;
     $config->update();
     $config = \Phire\Table\Config::findById('reply_email');
     $config->value = 'noreply@' . $domain;
     $config->update();
     if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/themes/phire/mail')) {
         $mailTmpl = file_get_contents($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/themes/phire/mail/install.txt');
     } else {
         $mailTmpl = file_get_contents(__DIR__ . '/../../../view/phire/mail/install.txt');
     }
     $mailTmpl = str_replace(array('Dear', 'Thank you for installing Phire CMS for', 'The website will be viewable here:', 'To manage the website, you can login to Phire here:', 'Thank You'), array($i18n->__('Dear'), $i18n->__('Thank you for installing Phire CMS for'), $i18n->__('The website will be viewable here:'), $i18n->__('To manage the website, you can login to Phire here:'), $i18n->__('Thank You')), $mailTmpl);
     // Send email verification
     $mail = new Mail($domain . ' - ' . $i18n->__('Phire CMS Installation'), $rcpt);
     $mail->from('noreply@' . $domain);
     $mail->setText($mailTmpl);
     $mail->send();
 }
Exemplo n.º 3
0
 /**
  * Send password reminder to user
  *
  * @param  string      $email
  * @param  \Pop\Config $config
  * @return void
  */
 public function sendReminder($email, $config)
 {
     $encOptions = $config->encryptionOptions->asArray();
     $user = Table\Users::findBy(array('email' => $email));
     if (isset($user->id)) {
         $type = Table\UserTypes::findById($user->type_id);
         if ($type->password_encryption == Auth\Auth::ENCRYPT_NONE) {
             $newPassword = $this->password;
             $newEncPassword = $newPassword;
             $msg = $this->i18n->__('Your username and password is:');
         } else {
             $newPassword = (string) String::random(8, String::ALPHANUM);
             $newEncPassword = self::encryptPassword($newPassword, $type->password_encryption, $encOptions);
             $msg = $this->i18n->__('Your password has been reset for security reasons. Your username and new password is:');
         }
         // Save new password
         $user->password = $newEncPassword;
         $user->save();
         // Get base path and domain
         $basePath = strtolower($type->type) != 'user' ? BASE_PATH . '/' . strtolower($type->type) : BASE_PATH . APP_URI;
         $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
         // Set recipient
         $rcpt = array('name' => $user->username, 'email' => $user->email, 'username' => $user->username, 'password' => $newPassword, 'login' => 'http://' . $_SERVER['HTTP_HOST'] . $basePath . '/login', 'domain' => $domain, 'message' => $msg);
         if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/themes/phire/mail/forgot.txt')) {
             $mailTmpl = file_get_contents($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/themes/phire/mail/forgot.txt');
         } else {
             $mailTmpl = file_get_contents(__DIR__ . '/../../../view/phire/mail/forgot.txt');
         }
         $mailTmpl = str_replace(array('Dear', 'Here is your password for', 'You can login at:', 'Thank You'), array($this->i18n->__('Dear'), $this->i18n->__('Here is your password for'), $this->i18n->__('You can login at:'), $this->i18n->__('Thank You')), $mailTmpl);
         // Send reminder
         $mail = new Mail($domain . ' - ' . $this->i18n->__('Password Reset'), $rcpt);
         $mail->from(Table\Config::findById('reply_email')->value);
         $mail->setText($mailTmpl);
         $mail->send();
     }
 }
Exemplo n.º 4
0
    $rcpts = array(array('name' => 'Test Smith', 'email' => '*****@*****.**'), array('name' => 'Someone Else', 'email' => '*****@*****.**'));
    $html = <<<HTMLMSG
<html>
<head>
    <title>
        Test HTML Email
    </title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
    <h1>Hello [{name}]</h1>
    <p>
        I'm just trying out this new Pop Mail Library component.
    </p>
    <p>
        Thanks,<br />
        Bob
    </p>
</body>
</html>

HTMLMSG;
    $mail = new Mail('Hello World!', $rcpts);
    $mail->from('*****@*****.**', 'Bob')->setHeaders(array('X-Mailer' => 'PHP/' . phpversion(), 'X-Priority' => '3'));
    $mail->setText("Hello [{name}],\n\nI'm just trying out this new Pop Mail component.\n\nThanks,\nBob\n\n");
    $mail->setHtml($html);
    $mail->send();
    echo 'Mail Sent!';
} catch (\Exception $e) {
    echo $e->getMessage();
}
Exemplo n.º 5
0
 /**
  * Send installation confirmation
  *
  * @param  Table\Users
  * @return void
  */
 public function sendConfirmation($user)
 {
     $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
     $schema = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://';
     // Set the recipient
     $rcpt = ['name' => $user->username, 'email' => $user->email, 'login' => $schema . $_SERVER['HTTP_HOST'] . BASE_PATH . APP_URI . '/login', 'domain' => $domain];
     // Check for an override template
     $mailTemplate = file_exists(CONTENT_ABS_PATH . '/phire/view/phire/mail/install.txt') ? CONTENT_ABS_PATH . '/phire/view/phire/mail/install.txt' : __DIR__ . '/../../view/phire/mail/install.txt';
     // Send email verification
     $mail = new Mail($domain . ' - Phire CMS Installation', $rcpt);
     $mail->from('noreply@' . $domain);
     $mail->setText(file_get_contents($mailTemplate));
     $mail->send();
     // Save domain
     $config = Table\Config::findById('domain');
     $config->value = $_SERVER['HTTP_HOST'];
     $config->save();
     // Save document root
     $config = Table\Config::findById('document_root');
     $config->value = $_SERVER['DOCUMENT_ROOT'];
     $config->save();
     // Save install timestamp
     $config = Table\Config::findById('installed_on');
     $config->value = (string) date('Y-m-d H:i:s');
     $config->save();
     $this->sendStats();
 }
Exemplo n.º 6
0
 public function testSaveTo()
 {
     $m = new Mail('Subject', array('name' => 'Bob Smith', 'email' => '*****@*****.**'), 'Hello World');
     $m->setHtml('Hello');
     $m->setText('Hello');
     $m->saveTo(__DIR__ . '/../tmp');
     $d = new Dir(__DIR__ . '/../tmp');
     $files = $d->getFiles();
     $exists = false;
     foreach ($files as $file) {
         if (strpos($file, 'popphpmail') !== false) {
             $exists = true;
             unlink(__DIR__ . '/../tmp/' . $file);
         }
     }
     $this->assertTrue($exists);
 }
Exemplo n.º 7
0
<?php

require_once '../../bootstrap.php';
use Pop\Mail\Mail;
try {
    $rcpts = array(array('name' => 'Test Smith', 'email' => '*****@*****.**'), array('name' => 'Someone Else', 'email' => '*****@*****.**'));
    $mail = new Mail('Hello World!', $rcpts);
    $mail->from('*****@*****.**', 'Bob');
    $mail->setText("Hello [{name}],\n\nI'm just trying out this new Pop Mail component.\n\nThanks,\nBob\n\n");
    // Save emails to a file format that can later be sent
    // by the Pop\Mail component or another external email
    // program, such as qmail, sendmail, etc.
    $mail->saveTo('../tmp');
    // Use the Pop\Mail component to send the saved email files.
    //$mail = new Mail();
    //$mail->sendFrom('../tmp', true);
    echo 'Mail Saved!';
} catch (\Exception $e) {
    echo $e->getMessage();
}
Exemplo n.º 8
0
 /**
  * Send user unsubscribe notification
  *
  * @param  Table\Users $user
  * @return void
  */
 protected function sendUnsubscribe(Table\Users $user)
 {
     $host = Table\Config::findById('domain')->value;
     $domain = str_replace('www.', '', $host);
     // Set the recipient
     $rcpt = ['name' => $user->username, 'email' => $user->email, 'domain' => $domain];
     // Check for an override template
     $mailTemplate = file_exists(CONTENT_ABS_PATH . '/phire/view/phire/mail/unsubscribe.txt') ? CONTENT_ABS_PATH . '/phire/view/phire/mail/unsubscribe.txt' : __DIR__ . '/../../view/phire/mail/unsubscribe.txt';
     // Send email verification
     $mail = new Mail($domain . ' - Unsubscribed', $rcpt);
     $mail->from('noreply@' . $domain);
     $mail->setText(file_get_contents($mailTemplate));
     $mail->send();
 }
Exemplo n.º 9
0
 /**
  * Method to process the form
  *
  * @return self
  */
 public function process()
 {
     $fields = $this->getFields();
     $submission = new Table\FormSubmissions(['form_id' => $this->id, 'timestamp' => date('Y-m-d H:i:s'), 'ip_address' => $_SERVER['REMOTE_ADDR']]);
     $submission->save();
     unset($fields['csrf']);
     unset($fields['captcha']);
     unset($fields['id']);
     unset($fields['submit']);
     $files = [];
     if ($_FILES) {
         foreach ($_FILES as $key => $value) {
             if (isset($value['tmp_name']) && !empty($value['tmp_name']) && class_exists('Phire\\Fields\\Model\\Field')) {
                 $upload = new Upload($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/files');
                 $filename = $upload->checkFilename($value['name'], $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/files');
                 $fields[$key] = $filename;
                 $files[] = $filename;
                 $upload->upload($value);
                 unset($_FILES[$key]);
             }
         }
     }
     $fv = new \Phire\Fields\Model\FieldValue();
     $values = $fv->save($fields, $submission->id, 'Phire\\Forms\\Model\\FormSubmission');
     $form = Table\Forms::findById($this->id);
     // If the form action is set
     if (!empty($form->action)) {
         $scheme = $form->force_ssl ? 'https://' : 'http://';
         $action = substr($form->action, 0, 4) == 'http' ? $form->action : $scheme . $_SERVER['HTTP_HOST'] . BASE_PATH . $form->action;
         if ($form->method == 'post') {
             $options = [CURLOPT_POST => true, CURLOPT_POSTFIELDS => $values, CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true];
         } else {
             $action .= '?' . http_build_query($values);
             $options = [CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true];
         }
         $curl = new \Pop\Http\Client\Curl($action, $options);
         $curl->send();
         unset($curl);
     }
     // Send the submission if the form "to" field is set
     if (!empty($form->to)) {
         $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
         $subject = $form->name . ' : ' . $domain;
         // Set the recipient
         $rcpt = ['email' => $form->to];
         $message = '';
         foreach ($values as $key => $value) {
             $message .= ucwords(str_replace('_', ' ', $key)) . ': ' . (is_array($value) ? implode(', ', $value) : $value) . PHP_EOL;
         }
         // Send form submission
         $mail = new Mail($subject, $rcpt);
         if (!empty($form->from)) {
             if (!empty($form->reply_to)) {
                 $mail->from($form->from, null, false)->replyTo($form->reply_to, null, false);
             } else {
                 $mail->from($form->from);
             }
         } else {
             if (!empty($form->reply_to)) {
                 $mail->replyTo($form->from);
             } else {
                 $mail->from('noreply@' . $domain);
             }
         }
         $mail->setText($message);
         if (count($files) > 0) {
             foreach ($files as $file) {
                 if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/files/' . $file)) {
                     $mail->attachFile($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/files/' . $file);
                 }
             }
         }
         $mail->send();
     }
     $this->clear();
     if (!empty($form->redirect)) {
         if (substr($form->redirect, 0, 4) == 'http' || substr($form->redirect, 0, 1) == '/') {
             $this->redirect = true;
             $redirect = substr($form->redirect, 0, 4) == 'http' ? $form->redirect : BASE_PATH . $form->redirect;
             header('Location: ' . $redirect);
             exit;
         } else {
             $this->message = $form->redirect;
         }
     }
     return $this;
 }