コード例 #1
0
ファイル: config.php プロジェクト: bibwho/MATPbootstrap
         @ftp_quit($result['connect_id']);
     }
 } else {
     $new_config['use_ftp'] = 0;
 }
 if (Mailer::is_online_host() == true) {
     $new_config['engine_send'] = ENGINE_UNIQ;
 }
 if (empty($new_config['smtp_pass'])) {
     $new_config['smtp_pass'] = $old_config['smtp_pass'];
 }
 if ($new_config['use_smtp'] && function_exists('fsockopen')) {
     preg_match('/^http(s)?:\\/\\/(.*?)\\/?$/i', $new_config['urlsite'], $match);
     require WAMAILER_DIR . '/class.smtp.php';
     $smtp = new Smtp();
     $result = $smtp->connect($new_config['smtp_host'], $new_config['smtp_port'], $new_config['smtp_user'], $new_config['smtp_pass'], $match[2]);
     if (!$result) {
         $error = true;
         $msg_error[] = sprintf(nl2br($lang['Message']['bad_smtp_param']), htmlspecialchars($smtp->msg_error));
     } else {
         $smtp->quit();
     }
 } else {
     $new_config['use_smtp'] = 0;
 }
 if (!$new_config['disable_stats'] && extension_loaded('gd')) {
     require WA_ROOTDIR . '/includes/functions.stats.php';
     if (!is_writable(WA_STATSDIR)) {
         $error = true;
         $msg_error[] = sprintf($lang['Message']['Dir_not_writable'], htmlspecialchars(wa_realpath(WA_STATSDIR)));
     }
コード例 #2
0
ファイル: mail.class.php プロジェクト: dalinhuang/concourse
 /**
  * 邮件发送
  *
  * @param: $name[string]        接收人姓名
  * @param: $email[string]       接收人邮件地址
  * @param: $subject[string]     邮件标题
  * @param: $content[string]     邮件内容
  * @param: $type[int]           0 普通邮件, 1 HTML邮件
  * @param: $notification[bool]  true 要求回执, false 不用回执
  *
  * @return boolean
  */
 function send($name, $email, $subject, $content, $type = 0, $notification = false)
 {
     @set_time_limit(3600);
     if (function_exists('ini_set')) {
         ini_set('max_execution_time', 3600);
     }
     global $_FANWE;
     $charset = 'utf-8';
     /* 邮件的头部信息 */
     $content_type = $type == 0 ? 'Content-Type: text/plain; charset=' . $charset : 'Content-Type: text/html; charset=' . $charset;
     $content = base64_encode($content);
     $headers = array();
     $headers[] = 'Date: ' . gmdate('D, j M Y H:i:s') . ' +0000';
     $headers[] = 'To: "' . '=?' . $charset . '?B?' . base64_encode($name) . '?=' . '" <' . $email . '>';
     $headers[] = 'From: "' . '=?' . $charset . '?B?' . base64_encode($_FANWE['setting']['site_name']) . '?=' . '" <' . $_FANWE['setting']['smtp_account'] . '>';
     $headers[] = 'Subject: ' . '=?' . $charset . '?B?' . base64_encode($subject) . '?=';
     $headers[] = $content_type . '; format=flowed';
     $headers[] = 'Content-Transfer-Encoding: base64';
     $headers[] = 'Content-Disposition: inline';
     if ($notification) {
         $headers[] = 'Disposition-Notification-To: ' . '=?' . $charset . '?B?' . base64_encode($_FANWE['setting']['site_name']) . '?=' . '" <' . $_FANWE['setting']['smtp_account'] . '>';
     }
     /* 获得邮件服务器的参数设置 */
     $params['host'] = $_FANWE['setting']['smtp_server'];
     $params['port'] = $_FANWE['setting']['smtp_port'];
     $params['user'] = $_FANWE['setting']['smtp_account'];
     $params['pass'] = $_FANWE['setting']['smtp_password'];
     if (empty($params['host']) || empty($params['port'])) {
         // 如果没有设置主机和端口直接返回 false
         $this->error[] = '邮件服务器设置信息不完整';
         return false;
     } else {
         // 发送邮件
         if (!function_exists('fsockopen')) {
             //如果fsockopen被禁用,直接返回
             $this->error[] = 'fsockopen函数被禁用';
             return false;
         }
         include fimport('class/smtp');
         static $smtp;
         $send_params['recipients'] = $email;
         $send_params['headers'] = $headers;
         $send_params['from'] = $_FANWE['setting']['smtp_account'];
         $send_params['body'] = $content;
         if (!isset($smtp)) {
             $smtp = new Smtp($params);
         }
         if ($smtp->connect() && $smtp->send($send_params)) {
             return true;
         } else {
             $err_msg = $smtp->error_msg();
             if (empty($err_msg)) {
                 $this->error[] = 'Unknown Error';
             } else {
                 if (strpos($err_msg, 'Failed to connect to server') !== false) {
                     $this->error[] = sprintf("无法连接到邮件服务器 %s", $params['host'] . ':' . $params['port']);
                 } else {
                     if (strpos($err_msg, 'AUTH command failed') !== false) {
                         $this->error[] = '邮件服务器验证帐号或密码不正确';
                     } elseif (strpos($err_msg, 'bad sequence of commands') !== false) {
                         $this->error[] = '服务器拒绝发送该邮件';
                     } else {
                         $this->error[] = $err_msg;
                     }
                 }
             }
             return false;
         }
     }
 }