setApiKey('api-key', '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'); $apiInstance = new TransactionalEmailsApi(new GuzzleHttp\Client(), $config); function send_email_with_brevo($to, $from, $subject, $message, $opt) { global $apiInstance; // Create a new SendSmtpEmail object $send_smtp_email = new SendSmtpEmail([ 'to' => $to, 'sender' => ['email' => 'crm@k-ep.hu', 'name' => 'K-ep Studio'], 'cc' => [['email' => 'crm@k-ep.hu', 'name' => 'K-ep Studio']], 'subject' => $subject, 'htmlContent' => $message ]); if(!empty($opt)) $send_smtp_email['params'] = $opt; if(!empty($opt["templateid"])) $send_smtp_email['templateId'] = $opt["templateid"]; else $send_smtp_email['templateId']=41; // add the options try { // Send the email using Brevo's TransactionalEmailsApi $response = $apiInstance->sendTransacEmail($send_smtp_email); // Log response or handle errors if needed //error_log("Email sent successfully."); } catch (Exception $e) { // Log the error // error_log("Error sending email: " . $e->getMessage()); } } $templateStatus = 'true'; // bool | Filter on the status of the template. Active = true, inactive = false $limit = 50; // int | Number of documents returned per page $offset = 0; // int | Index of the first document in the page $sort = "desc"; // string | Sort the results in the ascending/descending order of record creation. Default order is **descending** if `sort` is not passed try { $result = $apiInstance->getSmtpTemplates($templateStatus, $limit, $offset, $sort); } catch (Exception $e) { echo 'Exception when calling TransactionalEmailsApi->getSmtpTemplates: ', $e->getMessage(), PHP_EOL; } $template_arr=array(); $res=(array) $result; foreach($res as $key => $rows){ $r1= (array) $rows['templates']; foreach($r1 as $row){ $r2=(array) $row; foreach($r2 as $r3){ if($r3['isActive']==1) $template_arr[$r3['name']]=$r3['id']; } } } // Main logic for processing form submission or other actions if ($_POST["kod"] == '12345678987654321asdfghjklkjhgfdsa') { // Log the POST data //error_log("POST11: " . json_encode($_POST)); // Add your business logic here // Example: send an email using Brevo //Prepare $_POSZ if (isset($_POST["to"])) $email[0]['email'] = $_POST["to"]; else die(); if (isset($_POST["to_name"])) $email[0]['name'] = $_POST["to_name"]; else $email[0]['name']= $_POST["to"]; if (isset($_POST["from"])) $from=$_POST["from"]; else $from ="k-ep@k-ep.hu"; if (isset($_POST["subjects"])) $subject=$_POST["subjects"]; else $subject="K-ép Studio információs mail"; if (isset($_POST["uzenet"])) $uzenet="".$_POST["uzenet"].""; elseif (isset($_POST["szoveg"])) $uzenet=" K-ép Stúdió levele

" .$_POST["szoveg"]."

"; else $uzenet="

K-ép Studio információs mail

"; $option=array(); if (isset($_POST["template"])) { $option['templateid']=$template_arr[$_POST["template"]]; } if (isset($_POST["poitems"])){ $option['products']=$_POST["poitems"]; if (isset($_POST['pohead']["sum"])) $option['sum']=$_POST['pohead']["sum"]; if (isset($_POST['pohead']["note"])) $option['note']=$_POST['pohead']["note"]; if (isset($_POST['pohead']["deliver"])) $option['deliver']=$_POST['pohead']["deliver"]; if (isset($_POST['pohead']["payment"])) $option['payment']=$_POST['pohead']["payment"]; if (isset($_POST['pohead']["to_name"])) $option['name']=$_POST['pohead']["to_name"]; if (isset($_POST['pohead']["company"])) $option['company']=$_POST['pohead']["company"]; if (isset($_POST['pohead']["tel"])) $option['phone']=$_POST['pohead']["tel"]; if (isset($_POST['pohead']["address"])) $option['address']=$_POST['pohead']["address"]; } else{ if (isset($_POST["neve"])) $option['neve']=$_POST["neve"]; if (isset($_POST["product"])) $option['product']=$_POST["product"]; if (isset($_POST["webinar_url"])) $option['webinar_url']=$_POST["webinar_url"]; if (isset($_POST["ceg"])) $option['ceg']=$_POST["ceg"]; if (isset($_POST["regurl"])) $option['regurl']=$_POST["regurl"]; if (isset($_POST["link"])) $option['link']=$_POST["link"]; if (isset($_POST["mobile"])) $option['mobile']=$_POST["mobile"]; if (isset($_POST["uzenet"])) $option['uzenet']="".$_POST["uzenet"].""; if (isset($_POST["segment"])) $option['segment']=$_POST["segment"]; } $option['email']=$_POST["to"]; // Call the email sending send_email_with_brevo( $email, $from, $subject, $uzenet, $option); // Return success response or perform further actions as needed echo json_encode(array("success" => true, "data" => array(), "msg" => "Email sent successfully.")); } else { // Return error response if the verification code is incorrect echo json_encode(array("success" => false, "data" => array(), "msg" => "Invalid verification code.")); } ?>