码迷,mamicode.com
首页 > 其他好文 > 详细

发送电子邮件遇到问题

时间:2018-07-18 14:11:53      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:end   生成   xls   tle   href   vendor   file   登录页面   char   

一:相关配置 

   /**
     * 操作员明细报表
     */
    public function indexAction()
    {
        $service = $this->createService();

        $stocks = WmsStock::query($this->fetchSql);

        $path = SKIHAT_PATH_APP_MODULES . /wms/docs/waring.xls;
        $subjects = "库存预警通知(".date("Ymd").")";
        $body = "您好,以下商品库存不足(详情见附件),请及时补货!邮件由系统发出,请勿回复!";
        if ($stocks) {
            $service->excel($stocks, $path);
            $service->sendMail($path, $subjects, $body);
        }
        die();
    }

 

/**
     * 生成excel文件
     * @param $stocks
     * @param $path
     * @throws PHPExcel_Exception
     * @throws PHPExcel_Reader_Exception
     */
    public function excel($stocks, $path)
    {
        require_once(SKIHAT_PATH_VENDOR . /php-excel/PHPExcel.php);
        $objExcel = new PHPExcel();
        $title = 库存预警明细; //文件标题
        $sheet = $objExcel->setActiveSheetIndex(0);
        $sheet->setCellValue(A2, 仓库名称);
        $sheet->setCellValue(B2, 仓库id);
        $sheet->setCellValue(C2, " ".单品id);
        $sheet->setCellValue(D2, 单品名称);
        $sheet->setCellValue(E2, 品牌);

        $sheet->setCellValue(F2, 库存总量);
        $sheet->setCellValue(G2, 库存预警值);

        #合并单元格
        $objExcel->setActiveSheetIndex(0)->mergeCells(A1:I1);
        $objExcel->setActiveSheetIndex(0)->setCellValue(A1, $title);
        #设置font
        $objExcel->setActiveSheetIndex(0)->getStyle(A1)->getFont()->setSize(16);

        #设置居中(上下左右)
        $objExcel->setActiveSheetIndex(0)->getStyle(A1)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objExcel->setActiveSheetIndex(0)->getStyle(A1)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $rows = 3;
        foreach ($stocks as $item) {
            $sheet->setCellValue("A{$rows}", $item[house_name]);
            $sheet->setCellValue("B{$rows}", $item[house_id]);
            $sheet->setCellValue("C{$rows}", $item[sku_id]);
            $sheet->setCellValue("D{$rows}", $item[sku_name]);
            $sheet->setCellValue("E{$rows}", $item[brand_name]);
            $sheet->setCellValue("F{$rows}", $item[num]);
            $sheet->setCellValue("G{$rows}", $item[stock_warn]);

            ++$rows;
        }
        $objExcel->getActiveSheet()->setTitle(SetExcelName);
        $objExcel->setActiveSheetIndex(0);
        $objWriter = PHPExcel_IOFactory::createWriter($objExcel, Excel5);
        $objWriter->save($path);
    }

   /**
     * 发送邮件
     * @param $path
     * @param $subjects
     * @param $body
     * @return bool
     * @throws FileNotFoundException
     * @throws phpmailerException
     */
    public function sendMail($path, $subjects, $body)
    {
        //加载文件
        Skihat::import(php-mailer.php-mailer-autoload, SKIHAT_PATH_VENDOR);

        $emails = WmsWarnEmail::fetchAll(array(status=>1))->fetchObjects();

        $mail = new PHPMailer();

        //发送邮件服务器配置
        $mail->isSMTP();

        $mail->CharSet = "UTF-8";
        $mail->Encoding = "base64";

        $mail->Host = smtp.163.com;
        $mail->SMTPAuth = true;
        $mail->Username = xxxx@163.com; //发件邮箱
        $mail->Password = self::PASSWORD; 
        $mail->SMTPSecure = tls;
        $mail->Port =25;

        $mail->setFrom(xxxx@163.com, xxxx);

       //多人发送
        foreach($emails as $key=>$val){
            $mail->addAddress("$val->warn_email");
        }

        $mail->isHTML(true);
        $mail->Subject = $subjects; //主题
        $mail->Body = $body;  //内容

        $mail->AddAttachment($path, xxx.xls); //附件

        if (!$mail->send()) {
            echo "Mailer Error: " . $mail->ErrorInfo;
            return false;
        } else {
            echo "发送成功!!";
            return true;
        }
    }

 

二、报错

554 554 MI:SPB UserReject
0,smtp4,DtGowEBZfFjwIs5O2VSdBg--.25073S2 1322132210 please feedback at
554 MI:SPB 此用户不在网易允许的发信用户列表里
可能原因:                                                    
1、发送大量的广告信/推广信。(广告邮件)                            
2、发送了用户事先并未提出要求或者同意接收的邮件。(垃圾邮件)
3、发送的邮件包含大量不存在的收件人。 
请登录页面http://feedback.mail.126.com/antispam/complain.php?user=hz_viigoo@163.com 申请移除对xxx@xx.com  的相关限制
技术分享图片

 

网易相关错误码信息链接
 
 
       
 
 

发送电子邮件遇到问题

标签:end   生成   xls   tle   href   vendor   file   登录页面   char   

原文地址:https://www.cnblogs.com/sanqiyi/p/9328174.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!