Add: test_gmail

This commit is contained in:
jisangs committed 2022-04-20 20:37:14 +09:00
1 parent 9ea58eb556
commit 4703357e7d
3 files changed
+109 -10

No files matched your search

+54 -1
View File
@@ -1,6 +1,11 @@
<?php
header("Content-Type: application/json");
require_once("./../PHPMailer/src/PHPMailer.php");
require_once("./../PHPMailer/src/SMTP.php");
require_once("./../PHPMailer/src/Exception.php");
// variables for ncloud outbound mailer
$host_name_url = "https://mail.apigw.ntruss.com"; // 호스트 URL
$request_url= "/api/v1/mails"; // 요청 URI
@@ -193,7 +198,13 @@ function sendEmail($postParamData) {
$timestamp = getTimeStamp();
$signature = makeSignature($secret_key, $method, $request_url, $timestamp, $access_key);
cUrl($postParam, $timestamp, $signature);
// cUrl($postParam, $timestamp, $signature);
$recipients = getPostParamData($postParamData, "recipients");
$maestro_email = $recipients
$subject = getPostParamData($postParamData, "title");
$body = getPostParamData($postParamData, "body");
send_mail($address, $subject, $body);
}
@@ -276,6 +287,7 @@ function makeSignature($secret_key, $method, $uri, $timestamp, $access_key) {
return $signature;
}
/*
function cUrl($postParam, $timestamp, $signature) {
global $host_name_url, $request_url, $access_key, $secret_key, $api_key, $method, $request_id;
@@ -323,7 +335,48 @@ function cUrl($postParam, $timestamp, $signature) {
set_data("sendmail_error_postParam", $postParam);
}
}
*/
function send_mail($address, $subject, $body) {
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'support@jinaju.com'; // SMTP username
$mail->Password = '52napark!'; // SMTP password
$mail->CharSet = 'utf-8';
$mail->Encoding = "base64";
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
// $mail->SMTPSecure = 'ssl';
$mail->Port = 465; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->SetFrom('support@jinaju.com', '초코마에');
$mail->addAddress($address); // Add a recipient
// foreach ($addresses as $address) {
// $mail->addAddress($address);
// }
$mail->addReplyTo('support@jinaju.com', 'Information');
$mail->addCC('support@jinaju.com');
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $body;
$mail->send();
echo 'Message has been sent';
return true;
} catch (Exception $e) {
//echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
return false;
}
}