发送电子邮件遇到问题

Posted sanqiyi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了发送电子邮件遇到问题相关的知识,希望对你有一定的参考价值。

一:相关配置 

   /**
     * 操作员明细报表
     */
    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 = [email protected]; //发件邮箱
        $mail->Password = self::PASSWORD; 
        $mail->SMTPSecure = tls;
        $mail->Port =25;

        $mail->setFrom([email protected]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、发送的邮件包含大量不存在的收件人。 
技术分享图片

 

网易相关错误码信息链接
 
 
       
 
 





以上是关于发送电子邮件遇到问题的主要内容,如果未能解决你的问题,请参考以下文章

超实用的php代码片段

PHP必用代码片段

Perl - 使用带有身份验证的 MIME::Lite 发送电子邮件时遇到问题

C#和ASP.NET通过Gmail账户发送邮件的代码

代码片段

java发送邮件,遇到的奇葩问题