/** * @todo:發送郵件 * @param $sjr * @param $csr * @param $subject * @param $body * @param string $excelPath * @param string $pdfPath * @return bool * @throws \phpmailerException */ public function send_email($sjr, $csr, $subject, $body, $excelPath = '', $pdfPath = '', $from=0, $pdfArr=array()){ vendor('PHPMailer/PHPMailer'); vendor('PHPMailer/SMTP'); $poster = M('post_email')->where(array('attribute'=>$from))->find(); if (empty($poster)) { return false; } $mail = new \PHPMailer(); // $mail->SMTPDebug=1; $mail->isSMTP(); $mail->SMTPAuth=true; $mail->Host = 'smtp.exmail.qq.com'; $mail->SMTPSecure = 'ssl'; $mail->Port = 465; $mail->CharSet = 'UTF-8'; $mail->FromName = $poster['from_name']; $mail->Username = $poster['email']; $mail->Password = $poster['password']; $mail->From = $poster['email']; $mail->isHTML(TRUE); foreach($sjr as $to){ $to=trim($to); if(empty($to)) continue; $mail->addAddress($to); } foreach($csr as $to){ $to=trim($to); if(empty($to)) continue; $mail->addCC($to); } $mail->Subject = $subject; $mail->Body = $body ? $body : " "; if($excelPath) $mail->addAttachment($excelPath,$subject.'.xls'); if($pdfArr){ foreach ($pdfArr as $vo){ $mail->addAttachment(THINK_PATH.'..'.$vo['file'],$vo['name']); } }else{ if($pdfPath) $mail->addAttachment($pdfPath,$subject.'.pdf'); } $status = $mail->send(); if($status) { return true; }else{ return false; } }
tp發送郵件代碼
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.