From dfa190a9df7a3d635450109fa3d7a344840de65c Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Mon, 15 Apr 2019 15:55:05 +0900 Subject: [PATCH] Update mailgun.api.php --- helper/mailgun.api.php | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/helper/mailgun.api.php b/helper/mailgun.api.php index 5dc342a..7578002 100644 --- a/helper/mailgun.api.php +++ b/helper/mailgun.api.php @@ -7,8 +7,40 @@ * @documentation https://documentation.mailgun.com/en/latest/api-sending.html */ -if(!check_function_exists("mailgun_send_message")) { - function mailgun_send_message() { - // todo +if(!check_function_exists("mailgun_get_config")) { + function mailgun_get_config() { + $config = get_config(); + + return array( + "domain" => get_value_in_array("mailgun_domain", $config, ""), + "name" => get_value_in_array("mailgun_name", $config, "John Doe"), + "address" => get_value_in_array("mailgun_address", $config, ""), + "apikey" => get_value_in_array("mailgun_apikey", $config, ""), + ); + } +} + +if(!check_function_exists("mailgun_send_message")) { + function mailgun_send_message($to, $subject, $content) { + $response = false; + + $app_config = mailgun_get_config(); + + if(loadHelper("webpagetool")) { + $response = get_web_json(sprintf("https://api.mailgun.net/v3/%s/messages", $domain), array( + "headers" => array( + "Content-Type" => "multipart/form-data", + "Authentication" => array("Basic", "api", $app_config['apikey']), + ), + "data" => array( + "from" => sprintf("%s <%s>", $app_config['name'], $app_config['address']), + "to" => $to, + "subject" => $subject, + "text" => $content, + ), + )); + } + + return $response; } }