1. 程式人生 > >發送電子郵件遇到問題

發送電子郵件遇到問題

允許 xls obj ima feedback 單元格 cells ++ 內容

一:相關配置

   /**
     * 操作員明細報表
     */
    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(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/[email protected] 申請移除對[email protected] 的相關限制 申請界面 http://feedback.mail.126.com/antispam/[email protected] 技術分享圖片

網易相關錯誤碼信息鏈接 http://help.163.com/09/1224/17/5RAJ4LMH00753VB8.html

發送電子郵件遇到問題