From ed50a08f8e1bc1d8d635eadcc14a9c16ba501379 Mon Sep 17 00:00:00 2001 From: arman Date: Thu, 6 Feb 2025 22:14:42 +0000 Subject: [PATCH] Email setup --- common.inc.php | 83 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 76 insertions(+), 7 deletions(-) diff --git a/common.inc.php b/common.inc.php index 3ed54ebc..fc5fc7ed 100644 --- a/common.inc.php +++ b/common.inc.php @@ -956,27 +956,32 @@ function email_send($val, $to, $sub_subject = array(), $sub_body = array()) } $q = $pdo->prepare("SELECT * FROM emails WHERE val='$val'"); - if ($r = $q->fetch(PDO::FETCH_ASSOC)) { + $q->execute(); + if ($r = $q->fetch(PDO::FETCH_OBJ)) { + // we dont want to translate these, the messages themselves shoudl contain whatever languages they need $subject = $r->subject; $body = $r->body; $bodyhtml = $r->bodyhtml; + + + /* Eventually we should just do this with communication_replace_vars() */ if (count($sub_subject)) { foreach ($sub_subject as $sub_k => $sub_v) { - $subject = preg_replace("\[$sub_k\]", "$sub_v", $subject); - } + $subject = preg_replace("/\[$sub_k\]/", "$sub_v", $subject); + } } if (count($sub_body)) { foreach ($sub_body as $sub_k => $sub_v) { - $body = preg_replace("\[$sub_k\]", "$sub_v", $body); - } + $body = preg_replace("/\[$sub_k\]/", "$sub_v", $body); + } } if (count($sub_body)) { foreach ($sub_body as $sub_k => $sub_v) { - $bodyhtml = preg_replace("\[$sub_k\]", "$sub_v", $bodyhtml); + $bodyhtml = preg_replace("/\[$sub_k\]/", "$sub_v", $bodyhtml); } } @@ -991,7 +996,8 @@ function email_send($val, $to, $sub_subject = array(), $sub_body = array()) if ($fr) { // send using RMail // FIXME EMAIL - // //email_send_new($to, $fr, $subject, $body, $bodyhtml); + + email_send_new($to, $fr, $subject, $body, $bodyhtml); } else echo error(i18n("CRITICAL ERROR: email '%1' does not have a 'From' and the Fair Manager Email is not configured", array($val), array('email key name'))); } else { @@ -999,6 +1005,69 @@ function email_send($val, $to, $sub_subject = array(), $sub_body = array()) } } +function curl_request($to, $from, $subject, $text, $bodyhtml) +{ global $EMAIL_TRANSPORTER_URL; + + $url = $EMAIL_TRANSPORTER_URL; + + // The data you want to send via POST + // $fields = [ + // '__VIEWSTATE ' => $state, + // '__EVENTVALIDATION' => $valid, + // 'btnSubmit' => 'Submit' + // ]; + + // $fields = '{ + // "from" :"' . $from . '", + // "to" :"' . $to . '", + // "subject" :"' . $subject . '", + // "text" :"' . $text . '", + // "html": "' . $bodyhtml . '" + // }'; + + $fields = [ + "from" => $from, + "to" => $to, + "subject" => $subject, + "text" => $text, + "html" => $bodyhtml + ]; + + $fields_json= json_encode($fields); + error_log($fields_json); + + // url-ify the data for the POST + // $fields_string = http_build_query($fields); + + // open connection + $ch = curl_init(); + + // set the url, number of POST vars, POST data + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_json); + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + 'Content-Type: application/json', + 'Connection: Keep-Alive' + )); + curl_setopt($ch, CURLOPT_VERBOSE, true); + + // So that curl_exec returns the contents of the cURL; rather than echoing it + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + // execute post + $result = curl_exec($ch); + error_log('cURL Error: ' . curl_error($ch)); + error_log('result_from_function' . $result); + + return $result; +} + +function email_send_new($to, $from, $subject, $text, $bodyhtml) +{ + curl_request($to, $from, $subject, $text, $bodyhtml); +} + /* * require_once("Rmail/Rmail.php"); * require_once("Rmail/RFC822.php");