示例#1
0
文件: Mail.php 项目: vijinho/FFMVC
 /**
  * Return an instance of f3 \SMTP populated with application settings
  *
  * @param array $data
  * @return \SMTP
  */
 public static function &getMailer(array $data = []) : \SMTP
 {
     $f3 = \Base::instance();
     $smtp = new \SMTP($f3->get('email.host'), $f3->get('email.port'), $f3->get('email.scheme'), $f3->get('email.user'), $f3->get('email.pass'));
     $smtp->set('From', $f3->get('email.from'));
     // finally set other values like overrides
     foreach ($data as $k => $v) {
         $smtp->set($k, $v);
     }
     return $smtp;
 }
示例#2
0
 /**
  * adapter for SMTP
  *
  * @param string $subject
  * @param string $content
  * @param email  $receiver
  *
  * @return string done or error message
  */
 static function sendmail($subject, $content, $receiver)
 {
     $to_address = $receiver == "" ? f3()->get('inquiry_receiver') : $receiver;
     $smtp = new \SMTP(f3()->get('smtp_host'), f3()->get('smtp_port'), 'SSL', f3()->get('smtp_account'), f3()->get('smtp_password'));
     $smtp->set('From', '"' . f3()->get('smtp_name') . '" <' . f3()->get('smtp_account') . '>');
     $smtp->set('To', '<' . $to_address . '>');
     $smtp->set('Subject', $subject);
     $smtp->set('Errors-to', '<' . f3()->get('smtp_account') . '>');
     $smtp->set('Content-Type', 'text/html');
     $sent = $smtp->send($content, TRUE);
     $mylog = $smtp->log();
     if ($sent) {
         return 'Done';
     } else {
         return $mylog;
     }
 }
// then grab the user profile
try {
    $hybridauth = new Hybrid_Auth($hauth_config);
    $adapter = $hybridauth->authenticate($provider_name);
    $user_profile = $adapter->getUserProfile();
    $_SESSION['logged_in'] = 'ok';
    $username = $user_profile->email;
    $f3->set('SESSION.logged_in', 'ok');
    $user = new DB\SQL\Mapper($db, 'memos');
    $user->load(array('email = :username LIMIT 0,1', ':username' => $username));
    if ($user->dry()) {
        $user->role = 'subscriber';
        $user->created = date('Y-m-d H:i:s');
        // Send email to Admin with the good news: a new user!
        $smtp = new SMTP(SMTP_SERVER, SMTP_PORT, SMTP_PROTOCOL, SMTP_USERNAME, SMTP_PASSWORD);
        $smtp->set('From', '"Do Not Forget Me" <' . ADMIN_EMAIL . '>');
        $smtp->set('To', '<' . ADMIN_EMAIL . '>');
        $smtp->set('Subject', 'Yay, New DNFM User : '******'Errors-to', '<' . ADMIN_EMAIL . '>');
        $message = "On " . date('Y-m-d at H:i') . ", a new user subscribed to Do Not Forget Me!";
        $message .= "\n\nname: " . $user_profile->displayName;
        $message .= "\nemail: " . $user_profile->email;
        $message .= "\n\n\nPop up the champaign!";
        $sent = $smtp->send($message, TRUE);
        $mylog = $smtp->log();
    }
    $user->email = $username;
    if (!empty($user_profile->displayName)) {
        $user->name = $user_profile->displayName;
    }
    if (!empty($user_profile->firstName)) {
     echo '<pre>' . print_r($response, false) . '</pre>';
 } else {
     /**
      * It's all good. Go ahead with your application-specific authentication logic
      */
     $_SESSION['logged_in'] = 'ok';
     $username = $response['auth']['info']['email'];
     $f3->set('SESSION.logged_in', 'ok');
     $user = new DB\SQL\Mapper($db, 'memos');
     $user->load(array('email = :username LIMIT 0,1', ':username' => $username));
     if ($user->dry()) {
         $user->role = 'subscriber';
         $user->created = date('Y-m-d H:i:s');
         // Send email to Admin with the good news: a new user!
         $smtp = new SMTP(SMTP_SERVER, SMTP_PORT, SMTP_PROTOCOL, SMTP_USERNAME, SMTP_PASSWORD);
         $smtp->set('From', '"Do Not Forget Me" <' . ADMIN_EMAIL . '>');
         $smtp->set('To', '<' . ADMIN_EMAIL . '>');
         $smtp->set('Subject', 'Yay, New DNFM User : '******'auth']['info']['name']);
         $smtp->set('Errors-to', '<' . ADMIN_EMAIL . '>');
         $message = "On " . date('Y-m-d at H:i') . ", a new user subscribed to Do Not Forget Me!";
         $message .= "\n\nname: " . $response['auth']['info']['name'];
         $message .= "\nemail: " . $response['auth']['info']['email'];
         $message .= "\n\n\nPop up the champaign!";
         $sent = $smtp->send($message, TRUE);
         $mylog = $smtp->log();
     }
     $user->email = $username;
     if (!empty($response['auth']['info']['name'])) {
         $user->name = $response['auth']['info']['name'];
     }
     if (!empty($response['auth']['info']['first_name'])) {