Beispiel #1
1
 /**
  *功能:向非公司用户发送邮件
  *只支持接口调用
  *@author wxb
  *@date 2014/01/08
  */
 function act_sendByEmail()
 {
     if (empty($_REQUEST['toEmail'])) {
         self::$errCode = 123;
         self::$errMsg = 'miss email list';
         return false;
     }
     if (empty($_REQUEST['fromEmail'])) {
         self::$errCode = 124;
         self::$errMsg = 'miss from email';
         return false;
     }
     if (empty($_REQUEST['userEmail'])) {
         self::$errCode = 124;
         self::$errMsg = 'miss userName';
         return false;
     }
     if (empty($_REQUEST['content'])) {
         self::$errCode = 230;
         self::$errMsg = 'miss content';
         return false;
     }
     $_REQUEST = array_map('trim', $_REQUEST);
     $userEmail = urldecode($_REQUEST['userEmail']);
     $userExist = NoticeApiModel::userExistByEmail($userEmail);
     if (!$userExist) {
         self::$errCode = 230;
         self::$errMsg = 'miss user';
         return false;
     }
     $toEmail = urldecode($_REQUEST['toEmail']);
     $toEmail = preg_replace('/[,,]/i', ',', $toEmail);
     $fromEmail = urldecode($_REQUEST['fromEmail']);
     $fromEmail = preg_replace('/[,,]/i', ',', $fromEmail);
     $content = $_REQUEST['content'];
     $fromEmailArr = array();
     if (!isEmail($fromEmail)) {
         $wrongEmail[] = $fromEmail;
         self::$errCode = '266';
         self::$errMsg = '发送邮件格式有误';
         return false;
     } else {
         $to_name = strstr($fromEmail, '@', true);
         //自动截取
         $fromEmailArr[] = $to_name;
         $fromEmailArr[] = $fromEmail;
         $fromEmail = $fromEmailArr;
     }
     if (empty($_REQUEST['title'])) {
         $pattern = '/(^[^,,]+)[,,]{1}/';
         //取每一个逗号前字符为标题
         preg_match($pattern, $content, $matches);
         $title = $matches['1'] ? $matches['1'] : '^v^华成云商向你发了一封邮件';
         if (strlen($title) > 50) {
             $title = mb_substr($title, 0, 50);
         }
     } else {
         $title = $_REQUEST['title'];
     }
     $toEmail = explode(',', $toEmail);
     $wrongEmail = array();
     $toEmailArr = array();
     foreach ($toEmail as $toEmailVal) {
         //检查接收邮件地址
         $toEmailVal = trim($toEmailVal);
         if (!isEmail($toEmailVal)) {
             $wrongEmail[] = $toEmailVal;
             continue;
         }
         $to_name = strstr($toEmailVal, '@', true);
         //自动截取
         $toEmailArr[] = array('to_name' => $to_name, 'to_email' => $toEmailVal);
     }
     if (count($toEmailArr) == 0) {
         self::$errCode = 277;
         self::$errMsg = '无任何有效发送邮件地址';
         return false;
     }
     $ccArr = array();
     if (!empty($_REQUEST['cc'])) {
         $cc = urldecode($_REQUEST['cc']);
         $cc = preg_replace('/[,,]/i', ',', $cc);
         $cc = explode(',', $cc);
         foreach ($cc as $ccVal) {
             //检查抄送邮件地址
             $ccVal = trim($ccVal);
             if (!isEmail($ccVal)) {
                 $wrongEmail[] = $ccVal;
                 continue;
             }
             $to_name = strstr($ccVal, '@', true);
             //自动截取
             $ccArr[] = array('to_name' => $to_name, 'to_email' => $ccVal);
         }
         if (count($ccArr) == 0) {
             self::$errCode = 317;
             self::$errMsg = '无任何有效抄送邮件地址';
             return false;
         }
     }
     include_once WEB_PATH . "lib/sms.class.php";
     include_once WEB_PATH . "lib/class.phpmailer.php";
     include_once WEB_PATH . "lib/class.smtp.php";
     $mailObj = $mail;
     $status = newSendEmail($title, $content, $toEmailArr, $fromEmail, $ccArr, $mailObj);
     $sendFailArr = array();
     if ($status != '1') {
         if (is_array($status)) {
             $sendFailArr = $status[1];
             $emailSendFail = array_merge($wrongEmail, $status[1]);
             //返回数组 包含发送失败或都格式有如有误的邮件
         } else {
             $sendFailArr = explode(',', $status);
             //返回以,号隔开的发送失败者邮箱
             $emailSendFail = array_merge($wrongEmail, $sendFailArr);
         }
     }
     $table = "nt_api_email";
     $to_detail_all = array_merge($toEmailArr, $ccArr);
     foreach ($to_detail_all as $email_avaliable_val) {
         //记录到数据库
         $to_name = $email_avaliable_val['to_name'];
         if (in_array($to_name, $wrongEmail)) {
             continue;
         }
         $to_email = $email_avaliable_val['to_email'];
         if (in_array($to_email, $sendFailArr)) {
             $status = 0;
         } else {
             $status = 1;
         }
         $data = array("from_email" => $fromEmail['1'], "to_email" => $to_email, "content" => post_check($content), "from_name" => $fromEmail['0'], "to_name" => $to_name, "addtime" => time(), "status" => $status, "userEmail" => $userEmail);
         $result = NoticeApiModel::insert($data, $table);
     }
     $msg = '';
     //返回提示信息
     if (count($sendFailArr) > 0) {
         $msg = implode('|', $emailSendFail);
         if (empty($_REQUEST['losePerson'])) {
             $msg .= "  邮件发送失败";
         }
         self::$errCode = '354';
         self::$errMsg = $msg;
         return false;
     }
     self::$errCode = '111';
     self::$errMsg = 'ok';
     return true;
 }
Beispiel #2
0
     }
 }
 if (count($to_detail) == 0) {
     $errmsg_arr['2132'] = $losePerson ? implode(',', $to_arrs) : '无收件人数据或不应为本人';
     echo $format == 'json' ? error_json_notice('2132') : error_xml_notic('2131');
     exit;
 }
 //获取并过滤接收者信息 end
 //发送邮件
 $status = "";
 if (in_array("email", $type_arr)) {
     if (empty($title)) {
         $title = $from . '给您发了一条新的消息,请及时阅读【华成云商】';
     }
     $from_info = array($from, $from_email);
     $status = newSendEmail($title, $content, $email_avaliable, $from_info);
     $sendFailArr = array();
     if ($status != '1') {
         if (is_array($status)) {
             $emailSendFail = array_merge($emailSendFail, $status[1]);
             //返回数组
             $sendFailArr = $status[1];
         } else {
             $sendFailArr = explode(',', $status);
             //返回以,号隔开的发送失败者邮箱
             $emailSendFail = array_merge($emailSendFail, $sendFailArr);
         }
     }
     $table = "nt_email";
     foreach ($email_avaliable as $email_avaliable_val) {
         $to_email = $email_avaliable_val['to_email'];