diff --git a/config.example.json b/config.example.json index 895e46c..824c197 100644 --- a/config.example.json +++ b/config.example.json @@ -6,5 +6,11 @@ "mysql_user": "USER", "mysql_password": "PASS", "mysql_database": "db", - "amoj_regist": "h200" -} \ No newline at end of file + "amoj_regist": "h200", + "smtp_host": "mail.example.net", + "smtp_port": 587, + "smtp_auth": true, + "smtp_user": "USER", + "smtp_pass": "PASS", + "smtp_secure": "starttls" +} diff --git a/web/classes/UserUtil.php b/web/classes/UserUtil.php index 9dc63d6..ff65588 100644 --- a/web/classes/UserUtil.php +++ b/web/classes/UserUtil.php @@ -1,5 +1,6 @@ CharSet = PHPMailer::CHARSET_UTF8; $mail->Encoding = PHPMailer::ENCODING_QUOTED_PRINTABLE; - $mail->isSendmail(); + + $smtp_host = ConfigUtil::getInstance()->getConfig()["smtp_host"]; + if (!isset($smtp_host) || $smtp_host == "") { + $mail->isSendmail(); + } else { + $mail->isSMTP(); + $mail->Host = $smtp_host; + $mail->Port = ConfigUtil::getInstance()->getConfig()["smtp_port"]; + $mail->SMTPAuth = ConfigUtil::getInstance()->getConfig()["smtp_auth"]; + if ($mail->SMTPAuth) { + $mail->Username = ConfigUtil::getInstance()->getConfig()["smtp_user"]; + $mail->Password = ConfigUtil::getInstance()->getConfig()["smtp_pass"]; + } + switch (ConfigUtil::getInstance()->getConfig()["smtp_secure"]) { + case 'smtps': $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; break; + case 'starttls': $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; break; + } + } + $mail->setFrom($from); $mail->addAddress($to); $mail->Subject = $subject;