setQuery("SELECT * FROM `trf-details` WHERE `trf-details`.idtrfdetails='$idtrf'");
$checkpdffiles->execute();
$path = 'pdf';
$filename1 = $checkpdffiles->getColumnVal("pdffilename");
$file1 = $path . "/" . $filename1;
if (!empty($checkpdffiles->getColumnVal("pdffilename2"))) {
$filename2 = $checkpdffiles->getColumnVal("pdffilename2");
$file2 = $path . "/" . $filename2;
}
//Now include the following following files based
//on the correct file path. Third file is required only if you want to enable SMTP.
require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';
//mail to client
$mail = new PHPMailer(true);
try {
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $mailhost; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $mailusername; // SMTP username
$mail->Password = $mailpassword; // SMTP password
$mail->SMTPSecure = $mailmethod; // Enable encryption, 'ssl' also accepted
$mail->Port = $mailport;
$mmessage = "mailtrf";
include('include/mailhtml.php');
// Email body content
$trfnmbmail = $appformn . 'r' . $revnumb;
$htmlContent = $mailmessage1;
$mail->From = $fromaddresssmail;
$mail->FromName = 'CIMAC Application Form System';
$mail->addAddress($emailuser); // Add a recipient
$mail->addAttachment($file1); // Add attachments
if (!empty($checkpdffiles->getColumnVal("pdffilename2"))) {
$mail->addAttachment($file2);
} // Optional name
$mail->Subject = $appformn . 'r' . $revnumb;
$mail->Body = $htmlContent;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
error_log("Attempting to send email to: $emailuser with idtrf: $idtrf");
if ($adminconfirm == 'N') {
$mail->send();
error_log("Email sent successfully to: $emailuser with idtrf: $idtrf");
}
// echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent CL. Mailer Error: {$mail->ErrorInfo}";
}
// mail to CS
$mail = new PHPMailer(true);
try {
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $mailhost; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $mailusername; // SMTP username
$mail->Password = $mailpassword; // SMTP password
$mail->SMTPSecure = $mailmethod; // Enable encryption, 'ssl' also accepted
$mail->Port = $mailport;
$mmessage = "mailtrf";
// Email body content
$htmlContent = $mailmessage1;
$mail->From = $fromaddresssmail;
$mail->FromName = 'CIMAC Application Form System';
if (!empty($csmail)) {
$mail->addAddress($csmail); // Aggiunge il destinatario solo se non è vuoto
}
if (!empty($csmail2)) {
$mail->addAddress($csmail2);
}
if (!empty($csmail3)) {
$mail->addAddress($csmail3);
}
if (!empty($csmailccn)) {
$mail->addBCC($csmailccn);
}
$mail->Subject = $appformn . 'r' . $revnumb;;
$mail->Body = "Ciao! E' stato inserito un nuovo ETRF N. $trfnmbmail ";
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if ($adminconfirm == 'N') {
$mail->send();
}
// echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent CS. Mailer Error: {$mail->ErrorInfo}";
}
// mail REV to CS
// if rev is > 0
if ($revnumb > 0) {
//query to see the previous CS in charge
$revnumberprev = $revnumb - 1;
$trfprevrev = new WA_MySQLi_RS("trfprevrev", $cmctrfdb, 1);
$trfprevrev->setQuery("SELECT * FROM `trf-details` LEFT JOIN company ON `trf-details`.idcompany=company.idcompany WHERE `trf-details`.trfnumber='$ntrfmail' AND `trf-details`.revtrf='$revnumberprev'");
$trfprevrev->execute();
$csinchargeprev = $trfprevrev->getColumnVal("csincharge");
if ($csinchargeprev == 'ddondena') {
$mailincharge = 'd.dondena@cimac.it';
} elseif ($csinchargeprev == 'cboscaino') {
$mailincharge = 'c.boscaino@cimac.it';
} elseif ($csinchargeprev == 'aboscaino') {
$mailincharge = 'a.boscaino@cimac.it';
} elseif ($csinchargeprev == 'solocla') {
$mailincharge = 'info@acscreativesolutions.com';
} else {
$mailincharge = 'd.dondena@cimac.it';
}
// Define array with all CS mails
$csmailall = array($csmail, $csmail3);
// Extract the recipient that matches $mailincharge
$recipientTo = $mailincharge;
$recipientsCC = array_diff($csmailall, array($recipientTo));
$mail = new PHPMailer(true);
try {
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $mailhost; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $mailusername; // SMTP username
$mail->Password = $mailpassword; // SMTP password
$mail->SMTPSecure = $mailmethod; // Enable encryption, 'ssl' also accepted
$mail->Port = $mailport;
$mmessage = "mailtrf";
// Email body content
$htmlContent = $mailmessage1;
$mail->From = $fromaddresssmail;
$mail->FromName = 'CIMAC Application Form System';
$mail->addAddress($recipientTo); // Add the recipient in "To" field
foreach ($recipientsCC as $ccRecipient) {
$mail->addCC($ccRecipient); // Add recipients in "CC" field
}
$companynamemail = $trfprevrev->getColumnVal("companyname_company");
$descart = $trfprevrev->getColumnVal("sample_description");
$mail->Subject = $appformn . 'r' . $revnumb;
if ($_SESSION['langselect'] == 'it') {
// Imposta il testo in italiano
$mail->Body = "Ciao $csinchargeprev!
È stato inserito un nuovo ETRF N. $trfnmbmail.
" .
"Ragione Sociale = $companynamemail
" .
"Descrizione articolo $descart.
";
} else if ($_SESSION['langselect'] == 'en') {
// Imposta il testo in inglese
$mail->Body = "Hi $csinchargeprev!
A new ETRF No. $trfnmbmail has been submitted.
" .
"Company Name = $companynamemail
" .
"Item Description $descart.
";
} else {
// Imposta un valore di default o gestisci l'errore
$mail->Body = "Language setting is not recognized.";
}
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if ($adminconfirm == 'N') {
$mail->send();
}
// echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}
// exit();
/*
//$filename = $filepathname;
$path = 'pdf';
$file1 = $path . "/" . $filename1;
$file2 = $path . "/" . $filename2;
// Recipient
$to = $emailuser;
// Sender
$from = $fromaddresssmail;
$fromName = 'CIMAC Application Form System';
// Email subject
$subject = $appformn;
// Attachment file
$file = $file1;
$mmessage="mailtrf";
include('include/mailhtml.php');
// Email body content
$htmlContent = $mailmessage1;
// Header for sender info
$headers = "From: $fromName"." <".$from.">";
// Boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
// Multipart boundary
$message = "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" . $htmlContent . "\n\n";
// Preparing attachment
if(!empty($file) > 0){
if(is_file($file)){
$message .= "--{$mime_boundary}\n";
$fp = @fopen($file,"rb");
$data = @fread($fp,filesize($file));
@fclose($fp);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: application/octet-stream; name=\"".basename($file)."\"\n" .
"Content-Description: ".basename($file)."\n" .
"Content-Disposition: attachment;\n" . " filename=\"".basename($file)."\"; size=".filesize($file).";\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
}
}
$message .= "--{$mime_boundary}--";
$returnpath = "-f" . $from;
// Send email
$mail = @mail($to, $subject, $message, $headers, $returnpath);
*/
}
?>