<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ``` composer require phpmailer/phpmailer ``` 使用: ``` $config = [ 'userName' => '***@qq.com', 'password' => '***', 'host' => 'smtp.qq.com', 'port' => 465, 'receiveEmail' => '***@qq.com,***@qq.com', 'receiveNickname' => 'a,2', 'subject' => 'wo是主題', 'body' => $this->createHtml(), //html內容 'attachment' => 'runtime/uploads/files/2020-04-07/20200316.pdf,runtime/uploads/files/2020-04-07/20200316.docx', 'attachmentName' => 'pdf' ]; $email = new PHPMailerLib($config); return json($email->sendEmail()); ``` 整理的類 ``` <?php /** * +---------------------------------------------------------------------- * | ThinkPHP [ WE CAN DO IT JUST THINK ] * +---------------------------------------------------------------------- * | Copyright (c) 2020 ahai574 All rights reserved. * +---------------------------------------------------------------------- * | Licensed ( ++++ahai574++++ ) * +---------------------------------------------------------------------- * | Author: 阿海 <764882431@qq.com> * +---------------------------------------------------------------------- */ namespace app\common\library; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; class PHPMailerLib { /** * 開啟調試 0 不開啟 2開啟 */ private $SMTPDebug = 0; /** * 發送服務端 smtp.qq.com smtp.163.com */ private $host = 'smtp.qq.com'; /** * 是否需要開啟認證授權 */ private $SMTPAuth = true; /** * 發送的郵箱地址 */ private $userName = ''; /** * 郵箱授權密碼 */ private $password = ''; /** * 發送人的昵稱 */ private $sendNickname = ''; /** * 使用的協議 */ private $SMTPSecure = 'ssl'; /** * 發送的端口如:25 阿里云服務器是禁用這個端口的,所以建議是使用465端口來發送 */ private $port = 465; /** * 接收者的郵箱,使用英文逗號“,”分割 */ private $receiveEmail = ''; /** * 接收者的昵稱,使用英文逗號“,”分割 */ private $receiveNickname = ''; /** * 附件路徑 ,使用英文逗號“,”分割 */ private $attachment = null; /** * 附件文件對應的名稱 使用英文逗號“,”分割 */ private $attachmentName = ''; /** * 回復人的郵箱,使用英文逗號“,”分割 */ private $replyEmail = null; /** * 回復人的名稱,使用英文逗號“,”分割 */ private $replyNickname = ''; /** * 郵件的主題 標題 */ private $subject = ''; /** * 郵件的主體 html內容 */ private $body = ''; public function __construct($config = null) { if (is_null($config) || !is_array($config)) { throw new Exception("配置必須是數組,參數不能為空,請查看setMailerConf的參數"); } //批量設置參數 $this->setMailerConf($config); } /** * 批量設置 * 設置發送服務端的配置 * @param $array 數組 ['userName'=>'','password'=>'','sendNickname'=>'','host'=>'smtp.163.com','port'=>465,...] */ public function setMailerConf($array) { if (is_array($array)) { $this->SMTPDebug = isset($array['SMTPDebug']) ? $array['SMTPDebug'] : $this->SMTPDebug; $this->userName = isset($array['userName']) ? $array['userName'] : $this->userName; $this->password = isset($array['password']) ? $array['password'] : $this->password; $this->sendNickname = isset($array['sendNickname']) ? $this->setMailerCharset($array['sendNickname']) : $this->sendNickname; $this->host = isset($array['host']) ? $array['host'] : $this->host; $this->port = isset($array['port']) ? $array['port'] : $this->port; $this->receiveEmail = isset($array['receiveEmail']) ? $array['receiveEmail'] : $this->receiveEmail; $this->receiveNickname = isset($array['receiveNickname']) ? $this->setMailerCharset($array['receiveNickname']) : $this->receiveNickname; $this->replyEmail = isset($array['replyEmail']) ? $array['replyEmail'] : $this->replyEmail; $this->replyNickname = isset($array['replyNickname']) ? $this->setMailerCharset($array['replyNickname']) : $this->replyNickname; $this->attachment = isset($array['attachment']) ? $array['attachment'] : $this->attachment; $this->attachmentName = isset($array['attachmentName']) ? $this->setMailerCharset($array['attachmentName']) : $this->attachmentName; $this->subject = isset($array['subject']) ? $this->setMailerCharset($array['subject']) : $this->subject; $this->body = isset($array['body']) ? $array['body'] : $this->body; } return $this; } /** * 中文--轉碼 */ private function setMailerCharset($value) { return "=?utf-8?B?" . base64_encode($value) . "?="; } /** * 開啟調試 0 不開 2 開 */ public function setDebug($debug = 2) { $this->SMTPDebug = $debug; return $this; } /** * 設置附件 */ public function setAttachment($attachment = null, $attachmentName = null) { $this->attachment = $attachment; $this->attachmentName = $attachmentName; return $this; } /** * 設置內容主體 */ public function setBody($html) { $this->body = $html; return $this; } /** * 設置標題 */ public function setSubject($title) { $this->subject = $title; return $this; } /** * 設置收件人 及昵稱 */ public function setReceiveEmail($email, $nickName = null) { $this->receiveEmail = $email; $this->receiveNickname = $nickName; return $this; } /** * 設置回復人郵箱 昵稱 */ public function setReplyEmail($email, $nickName = null) { $this->replyEmail = $email; $this->replyNickname = $nickName; return $this; } /** * 發送郵件 */ public function sendEmail() { date_default_timezone_set("Asia/Shanghai"); $mail = new PHPMailer(true); try { //服務端 $mail->CharSet = 'utf-8'; //$mail->Encoding = "base64"; $mail->setLanguage('zh_cn', env('root_path') . "\\vendor\\phpMailer\\phpmailer\\language\\"); $mail->SMTPDebug = $this->SMTPDebug; $mail->isSMTP(); $mail->Host = $this->host; $mail->SMTPAuth = $this->SMTPAuth; $mail->Username = $this->userName; $mail->Password = $this->password; $mail->SMTPSecure = $this->SMTPSecure; $mail->Port = $this->port; //發送端 只能一個 $mail->setFrom($this->userName, $this->sendNickname); //接收端 if (is_null($this->receiveEmail) || empty($this->receiveEmail)) { throw new Exception("必須設置接收者的郵箱"); } $receiveEmails = explode(",", $this->receiveEmail); $receiveNicknames = explode(",", $this->receiveNickname); foreach ($receiveEmails as $key => $val) { $mail->addAddress($val, isset($receiveNicknames[$key]) ? $receiveNicknames[$key] : $val); //如果沒有昵稱則使用發送者的郵箱作為昵稱 } if (!is_null($this->replyEmail) || !empty($this->replyEmail)) { $replyEmails = explode(",", $this->replyEmail); $replyNicknames = explode(",", $this->replyNickname); foreach ($replyEmails as $key => $val) { $mail->addAddress($val, isset($replyNicknames[$key]) ? $replyNicknames[$key] : $val); //如果沒有昵稱則使用回復者的郵箱作為昵稱 } } // 添加附件 if (!is_null($this->attachment)) { $attachments = explode(",", $this->attachment); $attachmentsNames = explode(",", $this->attachmentName); foreach ($attachments as $key => $val) { $ext = substr($val, strrpos($val, '.')); $mail->addAttachment($val, isset($attachmentsNames[$key]) ? $attachmentsNames[$key] . $ext : "附件-" . ($key + 1) . $ext); } } $mail->isHTML(true); // Set email format to HTML $mail->Subject = $this->subject; $mail->Body = $this->body; if (!$mail->send()) { return ['result' => false, 'errorMsg' => $mail->ErrorInfo]; } else { return ['result' => true, 'msg' => '郵件發送成功']; } } catch (Exception $e) { return ['result' => false, 'errorMsg' => $mail->ErrorInfo]; } } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看