From 00daa1f23c6b2832da16fced7b53e68aa3f3516b Mon Sep 17 00:00:00 2001 From: "gary_chen\\gary_chen" Date: Thu, 15 Feb 2024 16:17:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=91=E7=9A=84=E5=AF=84=E4=BF=A1=E8=B7=9F?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E7=A8=8B=E5=BC=8F=E8=A2=AB=E7=A0=8D=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wms/class/Cmail.php | 62 ++++++++++++++++++++++++ wms/class/Cnotice.php | 109 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 wms/class/Cmail.php create mode 100644 wms/class/Cnotice.php diff --git a/wms/class/Cmail.php b/wms/class/Cmail.php new file mode 100644 index 00000000..51ed924b --- /dev/null +++ b/wms/class/Cmail.php @@ -0,0 +1,62 @@ +charset = "UTF-8"; + $this->host = "mail.masada.com.tw"; + $this->port = 25; + $this->smtp_user = "notice"; // 這裡填寫SMTP登入帳號, 例如 your.gmail.name@gmail.com 則填寫your.gmail.name + $this->smtp_pwd = "90493119"; // 這裡填寫SMTP登入密碼 + } + + function sendx($subject="", $em_body="", $sendlist=array(), $from="永佳捷科技", $bcc="", $files=array()) + { + if (!$sendlist) return; + $em_body = nl2br($em_body); + $em_body .= "

※此信件為系統發出信件,請勿直接回覆。

"; + + $mail = new PHPMailer(true); + $mail->IsHTML(true); //設定是否使用HTML格式 + $mail->CharSet = $this->charset; + $mail->isSMTP(); + $mail->SMTPAuth = true; + $mail->Host = $this->host; + $mail->Port = $this->port; + $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //使用SSL, 如果是TLS 請改為 PHPMailer::ENCRYPTION_STARTTLS + $mail->Username = $this->smtp_user; + $mail->Password = $this->smtp_pwd; + $mail->SMTPSecure = ""; + $mail->From = "notice@masada.com.tw"; + $mail->FromName = $from; + $mail->Subject = $subject; + $mail->Body = $em_body; + foreach ($sendlist as $v) { // $sendlist[0]=['M0044', 'jrbin@masada.com.tw'] + list($name, $email) = $v; + if ($email) $mail->addAddress($email, $name); + } + //$mail->addCC("personC@gmail.com", "person C"); + //$mail->addBCC("personD@gmail.com", "person D"); + //$mail->addAttachment("image1.jpg", "picture.jpg"); //設定附件, 對方會看到附件名稱為 picture.jpg + //print_r($mail);exit; + if (!$mail->Send()){ + // echo "Mailer error: " . $mail->ErrorInfo; + } else { + //echo "Email sent"; + } + } +} \ No newline at end of file diff --git a/wms/class/Cnotice.php b/wms/class/Cnotice.php new file mode 100644 index 00000000..970bf81c --- /dev/null +++ b/wms/class/Cnotice.php @@ -0,0 +1,109 @@ + false, + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_EMULATE_PREPARES => false, + PDO::ATTR_STRINGIFY_FETCHES => false, + PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4', + ]; + $pdo = new PDO('mysql:host=' . $host . ';port=' . $dbport . ';dbname=' . $dbname . '', $dbuser, $dbpassword, $options); + $pdo->exec('SET CHARACTER SET utf8mb4'); + return $pdo; + } catch (PDOException $e) { + die("Something wrong: {$e->getMessage()}"); + } + } + + /** + * 結束資料庫連線 + */ + function endConnectionDB($pdo) + { + unset($pdo); + } + + /** + * 提交消息 notice + * @param string $kind : 類別 1=系統 2=會議 + * @param int $related_id : 關聯序號 + * @param string $title : 標題 + * @param string $title : 內容 + * @param string $permission : 瀏覽權限 員編/ALL=全體 + * @param string $creater : 建立者 + * @param string $create_at : 建立時間 + */ + function sendx($data) + { + + $kind = $data['kind']; + $related_id = $data['related_id']; + $title = $data['title']; + $content = $data['content']; + $permission = $data['permission']; + $creater = $data['creater']; + $create_at = $data['create_at']; + + $pdo = $this->connectionDB(); + $pdo->exec('SET CHARACTER SET utf8mb4'); + $str = " + INSERT INTO `notice` (`kind`, `related_id`, `title`, `content`, `permission`, `creater`, `create_at`) + VALUES (?,?,?,?,?,?,?) + "; + + $sth = $pdo->prepare($str); + $sth->bindValue(1, $kind); + $sth->bindValue(2, $related_id); + $sth->bindValue(3, $title); + $sth->bindValue(4, $content); + $sth->bindValue(5, $permission); + $sth->bindValue(6, $creater); + $sth->bindValue(7, $create_at); + + $sth->execute(); + + $this->endConnectionDB($pdo); + } +} + +// $cn = new Cnotice(); +// $data = array( +// 'kind' => 1, +// 'related_id' => 1, +// 'title' => "標題", +// 'content' => "內容", +// 'permission' => "M0117", +// 'creater' => "M0117", +// 'create_at' => date("Y-m-d H:i:s") +// ); +// $cn->sendx($data);