Exemple #1
0
 function connect($params = array())
 {
     if (!isset($this->status)) {
         $obj = new Ecshop_smtp($params);
         if ($obj->connect()) {
             $obj->status = SMTP_STATUS_CONNECTED;
         }
         return $obj;
     } else {
         if (!empty($GLOBALS['LANG']['smtp_ssl'])) {
             $this->host = "ssl://" . $this->host;
         }
         $this->connection = @fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
         if ($this->connection === false) {
             $this->errors[] = 'Access is denied.';
             return false;
         }
         @socket_set_timeout($this->connection, 0, 250000);
         $greeting = $this->get_data();
         if (is_resource($this->connection)) {
             $this->status = 2;
             return $this->auth ? $this->ehlo() : $this->helo();
         } else {
             Import::basic()->log_write($errstr, __FILE__, __LINE__);
             //记录错误信息
             $this->errors[] = 'Failed to connect to server: ' . $errstr;
             return false;
         }
     }
 }
Exemple #2
0
 function ecshop_sendemail($data = array())
 {
     $name = $data['name'];
     $email = $data['email'];
     $subject = $data['subject'];
     $content = $data['content'];
     $type = $data['type'];
     $notification = $data['notification'];
     $charset = "utf-8";
     /**
      * 使用mail函数发送邮件
      */
     if ($GLOBALS['LANG']['mail_service'] == 0 && function_exists('mail')) {
         /* 邮件的头部信息 */
         $content_type = $type == 0 ? 'Content-Type: text/plain; charset=' . $charset : 'Content-Type: text/html; charset=' . $charset;
         $headers = array();
         $headers[] = 'From: "' . '=?' . $charset . '?B?' . base64_encode($GLOBALS['LANG']['site_name']) . '?=' . '" <' . $GLOBALS['LANG']['smtp_mail'] . '>';
         $headers[] = $content_type . '; format=flowed';
         if ($notification) {
             $headers[] = 'Disposition-Notification-To: ' . '=?' . $charset . '?B?' . base64_encode($GLOBALS['LANG']['site_name']) . '?=' . '" <' . $GLOBALS['LANG']['smtp_mail'] . '>';
         }
         $res = @mail($email, '=?' . $charset . '?B?' . base64_encode($subject) . '?=', $content, implode("\r\n", $headers));
         if (!$res) {
             Import::error()->add("邮件发送失败");
             return false;
         } else {
             return true;
         }
     } else {
         /* 邮件的头部信息 */
         $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($GLOBALS['LANG']['site_name']) . '?=' . '" <' . $GLOBALS['LANG']['smtp_mail'] . '>';
         $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($GLOBALS['LANG']['shop_name']) . '?=' . '" <' . $GLOBALS['LANG']['smtp_mail'] . '>';
         }
         /* 获得邮件服务器的参数设置 */
         $params['host'] = $GLOBALS['LANG']['smtp_host'];
         $params['port'] = $GLOBALS['LANG']['smtp_port'];
         $params['user'] = $GLOBALS['LANG']['smtp_user'];
         $params['pass'] = $GLOBALS['LANG']['smtp_pass'];
         if (empty($params['host']) || empty($params['port'])) {
             // 如果没有设置主机和端口直接返回 false
             Import::error()->add("邮件服务器的参数设置错误!");
             return false;
         } else {
             // 发送邮件
             if (!function_exists('fsockopen')) {
                 //如果fsockopen被禁用,直接返回
                 Import::error()->add("fsockopen被禁用");
                 return false;
             }
             $send_params['recipients'] = $email;
             $send_params['headers'] = $headers;
             $send_params['from'] = $GLOBALS['LANG']['smtp_mail'];
             $send_params['body'] = $content;
             $smtp = Import::ecshop_smtp($params);
             if (!isset($smtp)) {
                 include_once SYS_PATH . 'lib/class/cls_smtp.php';
                 $smtp = new Ecshop_smtp($params);
             }
             if ($smtp->connect() && $smtp->send($send_params)) {
                 return true;
             } else {
                 $err_msg = $smtp->error_msg();
                 if (empty($err_msg)) {
                     Import::error()->add('Unknown Error');
                 } else {
                     if (strpos($err_msg, 'Failed to connect to server') !== false) {
                         Import::error()->add("SMTP连接失败-" . $params['host'] . ':' . $params['port']);
                     } else {
                         if (strpos($err_msg, 'AUTH command failed') !== false) {
                             Import::error()->add("SMTP登录失败");
                         } elseif (strpos($err_msg, 'bad sequence of commands') !== false) {
                             Import::error()->add("SMTP拒绝错误");
                         } else {
                             print_r($err_msg);
                             echo "run..........";
                             Import::error()->add($err_msg);
                         }
                     }
                 }
                 return false;
             }
         }
     }
 }