摘要:有時(shí)候需要給運(yùn)營(yíng)定時(shí)發(fā)送表格數(shù)據(jù),方式是定時(shí)跑程序?qū)?shù)據(jù)生成一個(gè)然后郵件發(fā)送到運(yùn)營(yíng)郵箱,這里用來(lái)處理安裝下載用戶用戶昵稱公司名稱銷售功能版本次數(shù)最高消耗剩余時(shí)間使用百度老王從數(shù)據(jù)庫(kù)讀取的結(jié)果發(fā)送郵件郵件配置參考模板文件附件內(nèi)容發(fā)送時(shí)
有時(shí)候需要給運(yùn)營(yíng)定時(shí)發(fā)送表格數(shù)據(jù),方式是定時(shí)跑程序?qū)?shù)據(jù)生成一個(gè) excel 然后郵件發(fā)送到運(yùn)營(yíng)郵箱,這里用 laravel 來(lái)處理.
安裝 maatwebsite/excelcomposer reuqire maatwebsite/excel下載 excel
$titles = [ "用戶ID", "用戶昵稱", "公司名稱", "銷售", "功能版本", "次數(shù)", "最高", "消耗", "剩余", "時(shí)間" ]; //使用 Excel::create $data_arr=[$titles,["user_id"=>100,"nick_name"=>"xxx","company"=>"百度","seller_name"=>"老王","user_type"=>1,"times"=>666,"top"=>100,"flows"=>88,"rest"=>123,"time"=>date("YmdHis")]];//從數(shù)據(jù)庫(kù)讀取的結(jié)果 //http://www.maatwebsite.nl/laravel-excel/docs/export Excel::create("excel", function($excel) use($data_arr){ $excel->sheet("Sheetname", function($sheet) use($data_arr) { $sheet->fromArray($data_arr, null, "A1", false, false); }); })->store("xlsx",storage_path("excel/exports"));發(fā)送郵件
// https://docs.golaravel.com/docs/5.0/mail/ 郵件配置參考 #cat .env MAIL_DRIVER=smtp MAIL_HOST=smtp.exmail.qq.com MAIL_PORT=25 [email protected] MAIL_PASSWORD=xxx #cat config/mail.php //模板文件 #cat resources/views/emails/attachment.balde.php 附件內(nèi)容:{{$content}}
發(fā)送時(shí)間:{{date("Y-m-d H:i:s")}} //重試 3次 $tryTimes=3; do { $email="[email protected]"; $attachments=["file"=>storage_path("excel/exports")."/excel.xlsx"];//上面下載的 excel 附件 $subject="mail"; $cc="[email protected]";//抄送郵件 $sendResult = Mail::send("emails.attachment", ["content" => "發(fā)送內(nèi)容"], function ($message) use ($email, $attachments, $subject, $cc) { $message->to($email)->subject($subject); foreach ($attachments as $alias => $attachment) { $ext = pathinfo($attachment)["extension"]; $message->attach($attachment, ["as" => "=?UTF-8?B?" . base64_encode($alias) . "?=." . $ext]);// } if (!empty($cc)) { $message->cc($cc); } }); $tryTimes--; } while ($sendResult == 0 && $tryTimes); dd($sendResult);//發(fā)送成功 2
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/26039.html
摘要:一發(fā)送郵箱其實(shí)不難,不如說(shuō)挺簡(jiǎn)單的,首先還是現(xiàn)在注冊(cè)一個(gè)賬號(hào)并且設(shè)置如下圖授權(quán)碼很重要的,請(qǐng)好好記住,待會(huì)在的中要配置到的二如果以上你都做完了,那接下來(lái)就是配置了你的賬號(hào)你的客戶端授權(quán)密碼你的賬號(hào)賬號(hào)名三然后接下來(lái)就是配置路由以及在控制器上 一、發(fā)送郵箱其實(shí)不難,不如說(shuō)挺簡(jiǎn)單的,首先還是現(xiàn)在163注冊(cè)一個(gè)賬號(hào)并且設(shè)置如下圖 showImg(https://segmentfault.c...
摘要:慕課網(wǎng)發(fā)送郵件學(xué)習(xí)總結(jié)時(shí)間年月日星期六說(shuō)明本文部分內(nèi)容均來(lái)自慕課網(wǎng)。 慕課網(wǎng)《Spring Boot 發(fā)送郵件》學(xué)習(xí)總結(jié) 時(shí)間:2018年09月08日星期六 說(shuō)明:本文部分內(nèi)容均來(lái)自慕課網(wǎng)。@慕課網(wǎng):https://www.imooc.com 教學(xué)源碼:https://github.com/ityouknow/... 學(xué)習(xí)源碼:https://github.com/zccoder...
摘要:參數(shù)分別表示主機(jī)和端口。注意也可以在參數(shù)中指定端口號(hào)如,這樣就沒(méi)必要給出參數(shù)。當(dāng)需要發(fā)送附件的時(shí)候使用的就是這個(gè)類的一個(gè)子類。主要用來(lái)發(fā)送圖片普通文本郵件文本對(duì)象,其中是郵件內(nèi)容,郵件類型,可以是普通文本郵件,郵件編碼,可以是等等。 python發(fā)送郵件 準(zhǔn)備 python中發(fā)送郵件主要用的是smtplib和email兩個(gè)模塊,下面主要對(duì)這兩個(gè)模塊進(jìn)行講解 在講解之前需要準(zhǔn)備至少兩個(gè)...
閱讀 2979·2021-11-11 16:55
閱讀 546·2021-09-27 13:36
閱讀 1123·2021-09-22 15:35
閱讀 2951·2019-08-30 12:46
閱讀 3157·2019-08-26 17:02
閱讀 1858·2019-08-26 11:56
閱讀 1319·2019-08-26 11:47
閱讀 443·2019-08-23 17:01