Exemplo n.º 1
0
<?php

require_once "load.php";
$basic = Import::basic();
$data['name'] = '熊永金';
$data['email'] = isset($_POST['useremail']) ? trim($_POST['useremail']) : "";
$data['subject'] = '电子邮箱标题';
$data['content'] = '电子邮箱发布的内容';
$data['type'] = 1;
$data['notification'] = false;
if (isset($_POST['subemail'])) {
    if ($basic->ecshop_sendemail($data)) {
        echo "发送成功!";
    } else {
        $rt = Import::error()->get_all();
        print_r($rt);
        echo "发送失败!";
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>email 发送</title>
</head>

<body>
  <form name="form1" method="post" action="">
  <p>发送EMAIL    </p>
  <p>对方EMAIL:
Exemplo n.º 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;
             }
         }
     }
 }
Exemplo n.º 3
0
 function send_test($datas = array())
 {
     $basic = Import::basic();
     $data['name'] = '收件人姓名';
     $data['email'] = isset($datas['useremail']) ? trim($datas['useremail']) : "";
     $data['subject'] = '测试标题';
     $data['content'] = '你好,这是一封测试邮件,看到此内容时,表示测试成功!';
     $data['type'] = 1;
     $data['notification'] = false;
     if ($basic->ecshop_sendemail($data)) {
         echo "已测试成功!请稍后查看邮件!";
     } else {
         $rt = Import::error()->get_all();
         print_r($rt);
         echo "发送失败!";
     }
     exit;
 }