You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

62 lines
2.3 KiB

<?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";
}
}
}