declare(strict_types=1); date_default_timezone_set('Australia/Melbourne'); // ======================================= // CONFIG // ======================================= $csvDir = __DIR__ . '/data'; $csvFile = $csvDir . '/refer_executive.csv'; // kept for backward compatibility $logFile = $csvDir . '/mail_log.txt'; $headers = [ 'submitted_at', 'referred_name','role_title','referred_email','organisation', 'your_name','your_email', 'ip','user_agent' ]; $contactEmail = 'participation@executivecongresses.com'; $siteBase = 'https://executivecongresses.com/translational-medicine/'; $selfSlug = 'refer-executive'; define('SMTP_HOST', getenv('ECTMBICS_SMTP_HOST') ?: ''); define('SMTP_PORT', (int)(getenv('ECTMBICS_SMTP_PORT') ?: 587)); define('SMTP_USER', getenv('ECTMBICS_SMTP_USER') ?: 'participation@executivecongresses.com'); define('SMTP_PASS', getenv('ECTMBICS_SMTP_PASS') ?: ''); define('SMTP_ENCRYPTION', getenv('ECTMBICS_SMTP_ENCRYPTION') ?: 'tls'); define('MAIL_FROM_EMAIL', 'participation@executivecongresses.com'); define('MAIL_FROM_NAME', 'Executive Congresses — Translational Medicine & Biotech Innovation'); define('ADMIN_NOTIFY_EMAIL', 'participation@executivecongresses.com'); $confCode = 'ECTMBICS 2027'; $confName = '11th Executive Congress on Translational Medicine, Biotech Innovation & Clinical Strategy (ECTMBICS 2027)'; $confDates = '20–22 January 2027'; $confCity = 'Singapore'; // ======================================= // HELPERS // ======================================= function clean_str($s): string { $s = (string)$s; $s = preg_replace('/\s+/', ' ', trim($s)); $s = str_replace(["\r", "\n"], ' ', $s); if ($s !== '' && in_array($s[0], ['=', '+', '-', '@'], true)) { $s = "'" . $s; } return $s; } function ensure_dir(string $dir): void { if (!is_dir($dir)) { mkdir($dir, 0755, true); } } function ensure_csv_headers(string $csvFile, array $headers): void { if (!file_exists($csvFile) || filesize($csvFile) === 0) { $fp = fopen($csvFile, 'a'); if ($fp) { fputcsv($fp, $headers); fclose($fp); } } } function append_csv_row(string $csvFile, array $row): bool { $fp = fopen($csvFile, 'a'); if (!$fp) return false; if (!flock($fp, LOCK_EX)) { fclose($fp); return false; } $ok = fputcsv($fp, $row) !== false; flock($fp, LOCK_UN); fclose($fp); return $ok; } function write_log(string $file, string $message): void { @file_put_contents($file, '[' . date('Y-m-d H:i:s') . '] ' . $message . PHP_EOL, FILE_APPEND | LOCK_EX); } function e($v): string { return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8'); } function send_email(string $to, string $subject, string $html, string $text = '', array $replyTo = []): bool { $fromEmail = MAIL_FROM_EMAIL; $fromName = MAIL_FROM_NAME; $autoload = __DIR__ . '/vendor/autoload.php'; if (file_exists($autoload)) { require_once $autoload; } if (class_exists('\PHPMailer\PHPMailer\PHPMailer')) { try { $mail = new \PHPMailer\PHPMailer\PHPMailer(true); $mail->CharSet = 'UTF-8'; if (SMTP_HOST !== '' && SMTP_PASS !== '') { $mail->isSMTP(); $mail->Host = SMTP_HOST; $mail->SMTPAuth = true; $mail->Username = SMTP_USER; $mail->Password = SMTP_PASS; $mail->Port = (int)SMTP_PORT; $mail->SMTPSecure = (SMTP_ENCRYPTION === 'ssl') ? \PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_SMTPS : \PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_STARTTLS; } $mail->setFrom($fromEmail, $fromName); if (!empty($replyTo['email']) && filter_var($replyTo['email'], FILTER_VALIDATE_EMAIL)) { $mail->addReplyTo($replyTo['email'], $replyTo['name'] ?? ''); } $mail->addAddress($to); $mail->Subject = $subject; $mail->isHTML(true); $mail->Body = $html; $mail->AltBody = $text !== '' ? $text : trim(strip_tags(str_replace(['
','
','
'], "\n", $html))); $mail->send(); return true; } catch (\Throwable $t) {} } $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=UTF-8\r\n"; $headers .= 'From: "' . str_replace('"','', $fromName) . '" <' . $fromEmail . ">\r\n"; if (!empty($replyTo['email']) && filter_var($replyTo['email'], FILTER_VALIDATE_EMAIL)) { $headers .= 'Reply-To: "' . str_replace('"','', (string)($replyTo['name'] ?? '')) . '" <' . $replyTo['email'] . ">\r\n"; } $headers .= "X-Mailer: PHP/" . phpversion() . "\r\n"; return @mail($to, $subject, $html, $headers); } function email_wrap_html(string $title, string $bodyHtml): string { return '' . '' . '
' . '
' . '
' . '
' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '
' . '
' . '
' . $bodyHtml . '
' . '
' . 'Executive Congresses • 98 Theobalds Rd, London WC1X 8WB, UK' . '
' . '
' . '
' . 'If you did not submit this colleague referral, you can ignore this email.' . '
' . '
'; } // ======================================= // FLAGS // ======================================= $embed = (isset($_GET['embed']) && $_GET['embed'] === '1'); $ok = (isset($_GET['ok']) && $_GET['ok'] === '1'); $error = ''; // ======================================= // POST HANDLER // ======================================= if ($_SERVER['REQUEST_METHOD'] === 'POST') { ensure_dir($csvDir); ensure_csv_headers($csvFile, $headers); $website = trim((string)($_POST['website'] ?? '')); if ($website !== '') { $redir = $selfSlug . '?ok=1' . ($embed ? '&embed=1' : ''); header('Location: ' . $redir); exit; } $referred_name = clean_str($_POST['referred_name'] ?? ''); $role_title = clean_str($_POST['role_title'] ?? ''); $referred_email = clean_str($_POST['referred_email'] ?? ''); $organisation = clean_str($_POST['organisation'] ?? ''); $your_name = clean_str($_POST['your_name'] ?? ''); $your_email = clean_str($_POST['your_email'] ?? ''); if ($referred_name === '' || $role_title === '' || $organisation === '' || $your_name === '') { $error = 'Please complete the required fields.'; } elseif ($referred_email !== '' && !filter_var($referred_email, FILTER_VALIDATE_EMAIL)) { $error = 'Please enter a valid referred email address or leave it blank.'; } elseif ($your_email !== '' && !filter_var($your_email, FILTER_VALIDATE_EMAIL)) { $error = 'Please enter a valid email address for yourself or leave it blank.'; } elseif ( strlen($referred_name) > 160 || strlen($role_title) > 180 || strlen($referred_email) > 190 || strlen($organisation) > 190 || strlen($your_name) > 160 || strlen($your_email) > 190 ) { $error = 'One or more fields are too long. Please shorten the details and try again.'; } if ($error === '') { $submittedAt = date('Y-m-d H:i:s'); $ip = clean_str($_SERVER['REMOTE_ADDR'] ?? ''); $ua = clean_str($_SERVER['HTTP_USER_AGENT'] ?? ''); $row = [ $submittedAt, $referred_name, $role_title, $referred_email, $organisation, $your_name, $your_email, $ip, $ua ]; if (!append_csv_row($csvFile, $row)) { $error = 'Unable to save your referral right now. Please try again later.'; } else { $adminSubject = "New Colleague Referral — {$confCode} — {$referred_name}"; $adminBody = '

A new Colleague Referral has been submitted for review.

Submitted at'.htmlspecialchars($submittedAt, ENT_QUOTES, 'UTF-8').'
Conference'.htmlspecialchars($confName, ENT_QUOTES, 'UTF-8').' — '.htmlspecialchars($confDates, ENT_QUOTES, 'UTF-8').', '.htmlspecialchars($confCity, ENT_QUOTES, 'UTF-8').'
Referred name'.htmlspecialchars($referred_name, ENT_QUOTES, 'UTF-8').'
Role / title'.htmlspecialchars($role_title, ENT_QUOTES, 'UTF-8').'
Referred email'.($referred_email !== '' ? ''.htmlspecialchars($referred_email, ENT_QUOTES, 'UTF-8').'' : '—').'
Organisation'.htmlspecialchars($organisation, ENT_QUOTES, 'UTF-8').'
Referrer name'.htmlspecialchars($your_name, ENT_QUOTES, 'UTF-8').'
Referrer email'.($your_email !== '' ? ''.htmlspecialchars($your_email, ENT_QUOTES, 'UTF-8').'' : '—').'
IP'.htmlspecialchars($ip, ENT_QUOTES, 'UTF-8').'

Website: '.htmlspecialchars($siteBase . $selfSlug, ENT_QUOTES, 'UTF-8').'

'; $adminReplyEmail = $your_email !== '' ? $your_email : $contactEmail; $adminReplyName = $your_email !== '' ? $your_name : MAIL_FROM_NAME; $adminSent = send_email( ADMIN_NOTIFY_EMAIL, $adminSubject, email_wrap_html('New Colleague Referral', $adminBody), strip_tags($adminBody), [ 'email' => $adminReplyEmail, 'name' => $adminReplyName ] ); $ackSent = true; if ($your_email !== '') { $ackSubject = "Acknowledgement — colleague referral received — {$confCode}"; $ackBody = '

Dear '.htmlspecialchars($your_name, ENT_QUOTES, 'UTF-8').',

Thank you for recommending a colleague for '.htmlspecialchars($confCode, ENT_QUOTES, 'UTF-8').'. Your referral has been successfully received by our team.

This referral process helps us identify researchers, clinicians, academics, biotechnology and pharmaceutical professionals, digital health specialists, healthcare innovators, industry experts, emerging leaders, and other colleagues whose expertise may contribute to the scientific and professional programme.

Referral summary
Referred person: '.htmlspecialchars($referred_name, ENT_QUOTES, 'UTF-8').'
Role / Title: '.htmlspecialchars($role_title, ENT_QUOTES, 'UTF-8').'
Organisation: '.htmlspecialchars($organisation, ENT_QUOTES, 'UTF-8').'
Referred email: '.($referred_email !== '' ? htmlspecialchars($referred_email, ENT_QUOTES, 'UTF-8') : 'Not provided').'

Our team will review the referral and may contact the recommended colleague where their expertise aligns with the congress scope, speaker programme, delegate community, partnership activities, or other relevant participation opportunities. A referral does not guarantee a speaking role, abstract acceptance, registration, or any specific participation category.

For urgent questions, please contact us at '.htmlspecialchars($contactEmail, ENT_QUOTES, 'UTF-8').'.

Website: '.htmlspecialchars($siteBase, ENT_QUOTES, 'UTF-8').'

'; $ackSent = send_email( $your_email, $ackSubject, email_wrap_html('Referral received', $ackBody), strip_tags($ackBody), [ 'email' => $contactEmail, 'name' => MAIL_FROM_NAME ] ); } write_log( $logFile, 'Referral saved | referred=' . $referred_name . ' | referrer_email=' . ($your_email !== '' ? $your_email : 'none') . ' | admin_mail=' . ($adminSent ? 'OK' : 'FAIL') . ' | ack_mail=' . ($ackSent ? 'OK' : 'FAIL') ); $redir = $selfSlug . '?ok=1' . ($embed ? '&embed=1' : ''); header('Location: ' . $redir); exit; } } } ?>