/** * 功能:系統郵件發送函數 * @param string $to 內送郵件者郵箱 * @param string $name 內送郵件者名稱 * @param string $subject 郵件主題 * @param string $body 郵件內容 * @param string $attachment 附件列表 * @return boolean */function send_mail($to, $name, $subject = '', $body = '', $attachment = null, $config = '') { $config = is_array($config) ? $config : C('SYSTEM_EMAIL'); import('PHPMailer.phpmailer', VENDOR_PATH); //從PHPMailer目錄導class.phpmailer.php類檔案 $mail = new PHPMailer(); //PHPMailer對象 $mail->CharSet = 'UTF-8'; //設定郵件編碼,預設ISO-8859-1,如果發中文此項必須設定,否則亂碼 $mail->IsSMTP(); // 設定使用SMTP服務// $mail->IsHTML(true); $mail->SMTPDebug = 0; // 關閉SMTP調試功能 1 = errors and messages2 = messages only $mail->SMTPAuth = true; // 啟用 SMTP 驗證功能 if ($config['smtp_port'] == 465) $mail->SMTPSecure = 'ssl'; // 使用安全性通訊協定 $mail->Host = $config['smtp_host']; // SMTP 伺服器 $mail->Port = $config['smtp_port']; // SMTP伺服器的連接埠號碼 $mail->Username = $config['smtp_user']; // SMTP伺服器使用者名稱 $mail->Password = $config['smtp_pass']; // SMTP伺服器密碼 $mail->SetFrom($config['from_email'], $config['from_name']); $replyEmail = $config['reply_email'] ? $config['reply_email'] : $config['reply_email']; $replyName = $config['reply_name'] ? $config['reply_name'] : $config['reply_name']; $mail->AddReplyTo($replyEmail, $replyName); $mail->Subject = $subject; $mail->MsgHTML($body); $mail->AddAddress($to, $name); if (is_array($attachment)) { // 添加附件 foreach ($attachment as $file) { if (is_array($file)) { is_file($file['path']) && $mail->AddAttachment($file['path'], $file['name']); } else { is_file($file) && $mail->AddAttachment($file); } } } else { is_file($attachment) && $mail->AddAttachment($attachment); } return $mail->Send() ? true : $mail->ErrorInfo;}