Subversion Repositories php-qbpwcf

Rev

Rev 237 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php

/*

        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
    Copyright (C) 2014~2026 MIN ZHI, CHEN

    This file is part of QBPWCF.

    QBPWCF is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QBPWCF is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.

*/

#使用命名空間qbpwcf
namespace qbpwcf;

#assets dir
$assetsDir="assets of form::mail::pear_smtp_send";

#get mail server
#函式說明:
#將固定格式的字串分開,並回傳分開的結果.
#回傳結果:
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
#$result["error"],錯誤訊息陣列
#$result["function"],當前執行的函數名稱.
#$result["argu"],使用的參數.
#$result["oriStr"],要分割的原始字串內容
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
#$result["dataCounts"],爲總共分成幾段
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
#必填參數:
#$conf["stringIn"],字串,要處理的字串.
$conf["stringProcess::spiltString"]["stringIn"]=systemMailAcct;
#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
$conf["stringProcess::spiltString"]["spiltSymbol"]="@";
#可省略參數:
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
#$conf["allowEmptyStr"]="false";
#參考資料:
#無.
#備註:
#無.
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
unset($conf["stringProcess::spiltString"]);

#如果執行失敗
if($spiltString["status"]==="false"){

        #函式說明:
        #撰寫log
        #回傳結果:
        #$result["status"],狀態,"true"或"false".
        #$result["error"],錯誤訊息陣列.
        #$result["function"],當前函式的名稱.
        #$result["argu"],使用的參數.
        #必填參數:
        #$conf["path"],字串,log檔案的路徑與名稱.
        $conf["path"]=$logFile;
        #$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
        $conf["content"]=$spiltString;
        #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
        $conf["fileArgu"]=__FILE__;
        #可省略參數:
        #$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
        #$conf["rewrite"]="false";
        #參考資料:
        #無.
        #備註:
        #無.
        $record=logs::record($conf);
        unset($conf);

        #如果寫log失敗
        if($record["status"]==="false"){

                #印出結果
                var_dump($record);

                }#if end

        #結束執行,回傳錯誤代碼1
        exit(1);

        }#if end

#如果不是分成兩段
if($spiltString["dataCounts"]!==2){

        #函式說明:
        #撰寫log
        #回傳結果:
        #$result["status"],狀態,"true"或"false".
        #$result["error"],錯誤訊息陣列.
        #$result["function"],當前函式的名稱.
        #$result["argu"],使用的參數.
        #必填參數:
        #$conf["path"],字串,log檔案的路徑與名稱.
        $conf["path"]=$logFile;
        #$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
        $conf["content"]=$spiltString;
        #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
        $conf["fileArgu"]=__FILE__;
        #可省略參數:
        #$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
        #$conf["rewrite"]="false";
        #參考資料:
        #無.
        #備註:
        #無.
        $record=logs::record($conf);
        unset($conf);

        #如果寫log失敗
        if($record["status"]==="false"){

                #印出結果
                var_dump($record);

                }#if end

        #結束執行,回傳錯誤代碼1
        exit(1);

        }#if end

#函式說明:
#使用 php-pear-smtp 來透過SMTP伺服器寄信.
#回傳結果:
#$result["status"],執行正常與否,"true"代表正常;反之為"false".
#$result["error"],錯誤訊息陣列
#$result["function"],當前執行的函數.
#必填參數:
#$conf["mailServer"],字串,要使用的SMTP郵件伺服器網址.
$conf["mailServer"]="ssl://".$spiltString["dataArray"][1];
#$conf["username"],字串,用來登入郵件伺服器的帳號
$conf["username"]=$spiltString["dataArray"][0];
#$conf["password"],字串,用來登入郵件伺服器的密碼
$conf["password"]=systemMailPass;
#$conf["receiverMail"],陣列,收件人的信箱
$conf["receiverMail"]=array("liveuser@qbpwcf.org");
#$conf["subject"],字串,郵件的主題
$conf["subject"]="test send mail with pear net imap";
#$conf["plainBody"],字串,郵件本文的純文字內容.
$conf["plainBody"]="test send mail with pear net imap";
#$conf["htmlBody"]="";,字串,郵件本文的html內容,多媒體盡量不要用base64的方式來嵌入,因為大部分的郵件服務(Gmail)都不支援,如果是在單機上的郵件軟體就可能有支援,例如:Evolution.
$conf["htmlBody"]="<h1>test send mail with pear net imap</h1>";
#可省略參數:
#$conf["mailServerPort"],整數,smtp server的port,預設為465.
#$conf["mailServerPort"]=465;
#$conf["mailerMailDisplay"],字串,要顯示的寄件人信箱,預設爲 $conf["username"]
$conf["mailerMailDisplay"]=systemMailAcct;
#$conf["mailerNameDisplay"],字串,要顯示的寄件人姓名,預設爲 $conf["username"]
#$conf["mailerNameDisplay"]="liveuser";
#$conf["receiverMailDisplay"],陣列,要顯示的收件人信箱,預設爲 $conf["receiverMail"] 對應的元素.
#$conf["receiverMailDisplay"]="";
#$conf["receiverNameDisplay"],陣列,要顯示的收件人姓名,預設爲 $conf["receiverMail"] 對應的元素.
#$conf["receiverNameDisplay"]=array("liveuser");
#$conf["attachment"],陣列,每個要寄送的附件路徑與檔案名稱
$conf["attachment"]=array("index.php");
#$conf["attachmentName"],陣列,每個要寄送的附件顯示名稱,預設為$conf["attachment"]中的實際檔案名稱.
#$conf["attachmentName"]=array();
#$conf["attachmentMimeType"],陣列,每個附件的 mimeType,預設為"application/*".
#$conf["attachmentMimeType"]=array();
#$conf["userAgent"],字串,用於表示使用smtp服務的軟體資訊,預設為"Powerd by QBPWCF".
#$conf["userAgent"]="Powerd by QBPWCF";
#$conf["org"],字串,若要表示來源組織名稱,可在此設定.
$conf["org"]="北角網頁設計(https://www.qbpwcf.org)";
#$conf["notifyReceived"],字串,回報已讀通知,預設為"true"代表要;反之為"false".
#$conf["notifyReceived"]="true";
#$conf["signWithGPGid"],字串,用於簽署的gpg id,預設不使用.
$conf["signWithGPGid"]=systemMailAcct;
#$conf["signGpgThroughSocket"],字串,"trute"代表簽署gpg id的操作透過qbpwcf-uscok.service處理;預設為"false",直接用執行本程式的使用者來執行.
#$conf["signGpgThroughSocket"]="true";
#$conf["gpgPrivateKeyUser"],字串,當參數"signGpgThroughSocket"為"true"時,需要切換到哪個使用者才能取得gpg private key,預設使用運行qbpwcf-uscok.service的使用者.
#$conf["gpgPrivateKeyUser"]="";
#參考資料:
#官網=>http://pear.php.net/package/Net_SMTP
#Document=>https://github.com/pear/Net_SMTP
#SSL=>https://github.com/pear/Net_SMTP?tab=readme-ov-file#secure-connections
#Message-ID: =>https://datatracker.ietf.org/doc/html/rfc5322
#mail body boundary=>https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
#備註:
#需要php-pear-Net-SMTP
$pear_smtp_send=mail::pear_smtp_send($conf);
unset($conf);

#如果執行失敗
if($pear_smtp_send["status"]==="false"){

        #函式說明:
        #撰寫log
        #回傳結果:
        #$result["status"],狀態,"true"或"false".
        #$result["error"],錯誤訊息陣列.
        #$result["function"],當前函式的名稱.
        #$result["argu"],使用的參數.
        #必填參數:
        #$conf["path"],字串,log檔案的路徑與名稱.
        $conf["path"]=$logFile;
        #$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
        $conf["content"]=$pear_smtp_send;
        #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
        $conf["fileArgu"]=__FILE__;
        #可省略參數:
        #$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
        #$conf["rewrite"]="false";
        #參考資料:
        #無.
        #備註:
        #無.
        $record=logs::record($conf);
        unset($conf);

        #如果寫log失敗
        if($record["status"]==="false"){

                #印出結果
                var_dump($record);

                }#if end

        #結束執行,回傳錯誤代碼1
        exit(1);

        }#if end

?>