2022-09-17 20:50:50 +09:00
|
|
|
<?php
|
2024-09-19 20:57:39 +09:00
|
|
|
if (!defined('_GNUBOARD_'))
|
|
|
|
|
exit;
|
2022-09-17 20:50:50 +09:00
|
|
|
|
2024-09-28 13:03:15 +09:00
|
|
|
include_once G5_PHPMAILER_PATH . '/PHPMailerAutoload.php';
|
2022-09-17 20:50:50 +09:00
|
|
|
|
|
|
|
|
// 메일 보내기 (파일 여러개 첨부 가능)
|
|
|
|
|
// type : text=0, html=1, text+html=2
|
2024-09-19 20:57:39 +09:00
|
|
|
function mailer($fname, $fmail, $to, $subject, $content, $type = 0, $file = "", $cc = "", $bcc = "")
|
2022-09-17 20:50:50 +09:00
|
|
|
{
|
2024-09-19 20:57:39 +09:00
|
|
|
global $config;
|
|
|
|
|
global $g5;
|
2022-09-17 20:50:50 +09:00
|
|
|
|
2024-09-19 20:57:39 +09:00
|
|
|
// 메일발송 사용을 하지 않는다면
|
|
|
|
|
if (!$config['cf_email_use'])
|
|
|
|
|
return;
|
2022-09-17 20:50:50 +09:00
|
|
|
|
2024-09-19 20:57:39 +09:00
|
|
|
if ($type != 1)
|
|
|
|
|
$content = nl2br($content);
|
2022-09-17 20:50:50 +09:00
|
|
|
|
2024-09-28 13:03:15 +09:00
|
|
|
$result = run_replace('mailer', $fname, $fmail, $to, $subject, $content, $type, $file, $cc, $bcc);
|
|
|
|
|
|
|
|
|
|
if (is_array($result) && isset($result['return'])) {
|
|
|
|
|
return $result['return'];
|
2024-09-19 20:57:39 +09:00
|
|
|
}
|
2024-09-28 13:03:15 +09:00
|
|
|
|
|
|
|
|
$mail_send_result = false;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$mail = new PHPMailer(); // defaults to using php "mail()"
|
|
|
|
|
if (defined('G5_SMTP') && G5_SMTP) {
|
|
|
|
|
$mail->IsSMTP(); // telling the class to use SMTP
|
|
|
|
|
$mail->Host = G5_SMTP; // SMTP server
|
|
|
|
|
if (defined('G5_SMTP_PORT') && G5_SMTP_PORT)
|
|
|
|
|
$mail->Port = G5_SMTP_PORT;
|
2022-09-17 20:50:50 +09:00
|
|
|
}
|
2024-09-28 13:03:15 +09:00
|
|
|
$mail->CharSet = 'UTF-8';
|
|
|
|
|
$mail->From = $fmail;
|
|
|
|
|
$mail->FromName = $fname;
|
|
|
|
|
$mail->Subject = $subject;
|
|
|
|
|
$mail->AltBody = ""; // optional, comment out and test
|
|
|
|
|
$mail->msgHTML($content);
|
|
|
|
|
$mail->addAddress($to);
|
|
|
|
|
if ($cc)
|
|
|
|
|
$mail->addCC($cc);
|
|
|
|
|
if ($bcc)
|
|
|
|
|
$mail->addBCC($bcc);
|
|
|
|
|
//print_r2($file); exit;
|
|
|
|
|
if ($file != "") {
|
|
|
|
|
foreach ($file as $f) {
|
|
|
|
|
$mail->addAttachment($f['path'], $f['name']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$mail = run_replace('mail_options', $mail, $fname, $fmail, $to, $subject, $content, $type, $file, $cc, $bcc);
|
|
|
|
|
$mail_send_result = $mail->send();
|
|
|
|
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
|
2024-09-19 20:57:39 +09:00
|
|
|
}
|
2024-09-28 13:03:15 +09:00
|
|
|
|
|
|
|
|
EventHandler::triggerEvent("gnuboard.mail_send_result", $mail_send_result, $mail, $to, $cc, $bcc);
|
|
|
|
|
|
2024-09-19 20:57:39 +09:00
|
|
|
return $mail->send();
|
2022-09-17 20:50:50 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 파일을 첨부함
|
|
|
|
|
function attach_file($filename, $tmp_name)
|
|
|
|
|
{
|
2024-09-19 20:57:39 +09:00
|
|
|
// 서버에 업로드 되는 파일은 확장자를 주지 않는다. (보안 취약점)
|
|
|
|
|
$dest_file = G5_DATA_PATH . '/tmp/' . str_replace('/', '_', $tmp_name);
|
|
|
|
|
move_uploaded_file($tmp_name, $dest_file);
|
|
|
|
|
$tmpfile = array("name" => $filename, "path" => $dest_file);
|
|
|
|
|
return $tmpfile;
|
2022-09-17 20:50:50 +09:00
|
|
|
}
|