Files
assetmgt/api/v2/post/mailer.php
2025-08-29 15:01:30 +02:00

80 lines
2.7 KiB
PHP

<?php
defined($security_key) or exit;
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
//------------------------------------------
// Products attributes
//------------------------------------------
//Connect to DB
$pdo = dbConnect($dbname);
//CONTENT FROM API (POST)
$post_content = json_decode($input,true);
//VALIDATE INPUT CRITERIA
if (isset($post_content['type']) && $post_content['type'] !=''){
//GET TYPE OF EMAIL
$mail_type = $post_content['type'] ?? '';
$mail_content = isset($post_content['content']) ? $post_content['content']: '';
$mail_subject = isset($post_content['subject']) ? $post_content['subject']: '';
$mail_to = isset($post_content['to']) ? $post_content['to']: email;
//QUERY AND VERIFY ALLOWED
if (isAllowed('mailer',$profile,$permission,'U') === 1){
//CHECK MAIL TYPE
switch ($mail_type) {
case 'contactform':
//GET TEMPLATE
$mail_location = (file_exists($_SERVER['DOCUMENT_ROOT'].'/custom/'.$domain.'/mail/email_template_contactform.php') ? $_SERVER['DOCUMENT_ROOT'].'/custom/'.$domain.'/mail/email_template_contactform.php' : './assets/mail/email_template_contactform.php');
include_once $mail_location;
//SEND MAIL
send_mail($mail_to,$mail_subject,$message,'','');
echo json_encode(array('status' => 'send'));
break;
case 'register_identity':
//SEND MAIL
send_mail($mail_to,$mail_subject,$mail_content,'','');
echo json_encode(array('status' => 'send'));
break;
case 'reset':
//GET TEMPLATE
$mail_location = (file_exists($_SERVER['DOCUMENT_ROOT'].'/custom/'.$domain.'/mail/email_template_reset.php') ? $_SERVER['DOCUMENT_ROOT'].'/custom/'.$domain.'/mail/email_template_reset.php' : './assets/mail/email_template_reset.php');
include_once $mail_location;
//SEND MAIL
send_mail($mail_to,$subject,$message,'','');
break;
case 'sendInvite':
// Get appointment data from mail_content
$appointment = $post_content['content'];
if ($appointment && isset($appointment['starttime']) && isset($appointment['endtime'])) {
sendIcsCalendar($appointment, $post_content['to'], $post_content['subject']);
echo json_encode(array('status' => 'send'));
} else {
echo json_encode(array('status' => 'error', 'message' => 'Invalid appointment data'));
}
break;
}
}
else
{
//do nothing
}
} else {
exit;
}
?>