2 changed files with 171 additions and 0 deletions
@ -0,0 +1,62 @@ |
|||||
|
<?php |
||||
|
use PHPMailer\PHPMailer\PHPMailer; |
||||
|
use PHPMailer\PHPMailer\SMTP; |
||||
|
use PHPMailer\PHPMailer\Exception; |
||||
|
|
||||
|
class Cmail |
||||
|
{ |
||||
|
public $charset = ""; |
||||
|
public $host = ""; |
||||
|
public $port = ""; |
||||
|
public $smtp_user = ""; |
||||
|
public $smtp_pwd = ""; |
||||
|
|
||||
|
function __construct($charset='', $fromemail='') |
||||
|
{ |
||||
|
include dirname(__DIR__)."/PHPMailer/Exception.php"; |
||||
|
include dirname(__DIR__)."/PHPMailer/PHPMailer.php"; |
||||
|
include dirname(__DIR__)."/PHPMailer/SMTP.php"; |
||||
|
|
||||
|
$this->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 .= "<p>※此信件為系統發出信件,請勿直接回覆。</p>"; |
||||
|
|
||||
|
$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"; |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,109 @@ |
|||||
|
<?php |
||||
|
//ini_set('display_errors', 'on'); |
||||
|
|
||||
|
class Cnotice |
||||
|
{ |
||||
|
|
||||
|
function __construct() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
function connectionDB() |
||||
|
{ |
||||
|
$envFile = __DIR__ . '/../../.env'; |
||||
|
if (file_exists($envFile)) { |
||||
|
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
||||
|
if ($lines !== false) { |
||||
|
foreach ($lines as $line) { |
||||
|
list($key, $value) = explode('=', $line, 2); |
||||
|
$key = trim($key); |
||||
|
$value = trim($value); |
||||
|
putenv("$key=$value"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
date_default_timezone_set("Asia/Taipei"); |
||||
|
$host = getenv('DB_HOST'); |
||||
|
$dbport = getenv('DB_PORT'); |
||||
|
$dbuser = getenv('DB_USERNAME'); |
||||
|
$dbpassword = getenv('DB_PASSWORD'); |
||||
|
$dbname = getenv('DB_DATABASE'); |
||||
|
|
||||
|
try { |
||||
|
$options = [ |
||||
|
PDO::ATTR_PERSISTENT => 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); |
Loading…
Reference in new issue