function hesk_testSMTP() { global $hesk_settings, $hesklang, $set; // Get variables $set['smtp_host_name'] = hesk_input(hesk_POST('s_smtp_host_name', 'localhost')); $set['smtp_host_port'] = intval(hesk_POST('s_smtp_host_port', 25)); $set['smtp_timeout'] = intval(hesk_POST('s_smtp_timeout', 10)); $set['smtp_ssl'] = empty($_POST['s_smtp_ssl']) ? 0 : 1; $set['smtp_tls'] = empty($_POST['s_smtp_tls']) ? 0 : 1; $set['smtp_user'] = hesk_input(hesk_POST('s_smtp_user')); $set['smtp_password'] = hesk_input(hesk_POST('s_smtp_password')); // Initiate SMTP class and set parameters require_once HESK_PATH . 'inc/mail/smtp.php'; $smtp = new smtp_class(); $smtp->host_name = $set['smtp_host_name']; $smtp->host_port = $set['smtp_host_port']; $smtp->timeout = $set['smtp_timeout']; $smtp->ssl = $set['smtp_ssl']; $smtp->start_tls = $set['smtp_tls']; $smtp->user = $set['smtp_user']; $smtp->password = hesk_htmlspecialchars_decode(stripslashes($set['smtp_password'])); $smtp->debug = 1; if (strlen($set['smtp_user']) || strlen($set['smtp_password'])) { require_once HESK_PATH . 'inc/mail/sasl/sasl.php'; } $connection_OK = false; ob_start(); // Test connection if ($smtp->Connect()) { // SMTP connect successful $connection_OK = true; $smtp->Disconnect(); } else { global $smtp_error, $smtp_log; $smtp_error = ucfirst($smtp->error); $smtp_log = ob_get_contents(); } $smtp_log = ob_get_contents(); ob_end_clean(); return $connection_OK; }
stream_wrapper_unregister('pop3'); } // Register the pop3 stream handler class stream_wrapper_register('pop3', 'pop3_stream'); // Setup required variables $pop3 = new pop3_class(); $pop3->hostname = $hesk_settings['pop3_host_name']; $pop3->port = $hesk_settings['pop3_host_port']; $pop3->tls = $hesk_settings['pop3_tls']; $pop3->debug = 0; $pop3->join_continuation_header_lines = 1; // Connect to POP3 if (($error = $pop3->Open()) == "") { echo $hesk_settings['debug_mode'] ? "<pre>Connected to the POP3 server "" . $pop3->hostname . "".</pre>\n" : ''; // Authenticate if (($error = $pop3->Login($hesk_settings['pop3_user'], hesk_htmlspecialchars_decode($hesk_settings['pop3_password']))) == "") { echo $hesk_settings['debug_mode'] ? "<pre>User "" . $hesk_settings['pop3_user'] . "" logged in.</pre>\n" : ''; // Get number of messages and total size if (($error = $pop3->Statistics($messages, $size)) == "") { echo $hesk_settings['debug_mode'] ? "<pre>There are {$messages} messages in the mail box with a total of {$size} bytes.</pre>\n" : ''; // If we have any messages, process them if ($messages > 0) { // Connect to the database hesk_dbConnect(); for ($message = 1; $message <= $messages; $message++) { echo $hesk_settings['debug_mode'] ? "<pre>Parsing message {$message} of {$messages}.</pre>\n" : ''; $pop3->GetConnectionName($connection_name); $message_file = 'pop3://' . $connection_name . '/' . $message; // Parse the incoming email $results = parser($message_file); // Convert email into a ticket (or new reply)
function hesk_mail($to, $subject, $message, $htmlMessage, $cc = array(), $bcc = array(), $hasMessageTag = false) { global $hesk_settings, $hesklang, $modsForHesk_settings, $ticket; // Demo mode if (defined('HESK_DEMO')) { return true; } // Encode subject to UTF-8 $subject = "=?UTF-8?B?" . base64_encode(hesk_html_entity_decode($subject)) . "?="; // Auto-generate URLs for HTML-formatted emails $htmlMessage = hesk_makeURL($htmlMessage, '', false); // Setup "name <email>" for headers if ($hesk_settings['noreply_name']) { $hesk_settings['from_header'] = "=?UTF-8?B?" . base64_encode(hesk_html_entity_decode($hesk_settings['noreply_name'])) . "?= <" . $hesk_settings['noreply_mail'] . ">"; } else { $hesk_settings['from_header'] = $hesk_settings['noreply_mail']; } // Uncomment for debugging # echo "<p>TO: $to<br >SUBJECT: $subject<br >MSG: $message</p>"; # return true; // Use mailgun if ($modsForHesk_settings['use_mailgun']) { ob_start(); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.mailgun.net/v2/" . $modsForHesk_settings['mailgun_domain'] . "/messages"); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, 'api:' . $modsForHesk_settings['mailgun_api_key']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_POST, true); $postfields = array('from' => $hesk_settings['from_header'], 'to' => $to, 'h:Reply-To' => $hesk_settings['from_header'], 'subject' => $subject, 'text' => $message); if (count($cc) > 0) { $postfields['cc'] = implode(',', $cc); } if (count($bcc) > 0) { $postfields['bcc'] = implode(',', $bcc); } if ($modsForHesk_settings['html_emails']) { $postfields['html'] = $htmlMessage; } if ($hasMessageTag && $modsForHesk_settings['attachments'] && $hesk_settings['attachments']['use'] && isset($ticket['attachments']) && strlen($ticket['attachments'])) { $postfields = processDirectAttachments('mailgun', $postfields); } curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); $result = curl_exec($ch); curl_close($ch); $tmp = trim(ob_get_contents()); ob_end_clean(); return strlen($tmp) ? $tmp : true; } $outerboundary = sha1(uniqid()); $innerboundary = sha1(uniqid()); if ($outerboundary == $innerboundary) { $innerboundary .= '1'; } $plaintextMessage = $message; $message = "--" . $outerboundary . "\n"; $message .= "Content-Type: multipart/alternative; boundary=\"" . $innerboundary . "\"\n\n"; $message .= "--" . $innerboundary . "\n"; $message .= "Content-Type: text/plain; charset=" . $hesklang['ENCODING'] . "\n\n"; $message .= $plaintextMessage . "\n\n"; //Prepare the message for HTML or non-html if ($modsForHesk_settings['html_emails']) { $message .= "--" . $innerboundary . "\n"; $message .= "Content-Type: text/html; charset=" . $hesklang['ENCODING'] . "\n\n"; $message .= $htmlMessage . "\n\n"; } //-- Close the email $message .= "--" . $innerboundary . "--"; // Use PHP's mail function if (!$hesk_settings['smtp']) { // Set additional headers $headers = ''; $headers .= "MIME-Version: 1.0\n"; $headers .= "From: {$hesk_settings['from_header']}\n"; if (count($cc) > 0) { $headers .= "Cc: " . implode(',', $cc); } if (count($bcc) > 0) { $headers .= "Bcc: " . implode(',', $bcc); } $headers .= "Reply-To: {$hesk_settings['from_header']}\n"; $headers .= "Return-Path: {$hesk_settings['webmaster_mail']}\n"; $headers .= "Date: " . date(DATE_RFC2822) . "\n"; $headers .= "Content-Type: multipart/mixed;boundary=\"" . $outerboundary . "\""; // Add attachments if necessary if ($hasMessageTag && $modsForHesk_settings['attachments'] && $hesk_settings['attachments']['use'] && isset($ticket['attachments']) && strlen($ticket['attachments'])) { $message .= processDirectAttachments('phpmail', NULL, $outerboundary); } $message .= "\n\n" . '--' . $outerboundary . '--'; // Send using PHP mail() function ob_start(); mail($to, $subject, $message, $headers); $tmp = trim(ob_get_contents()); ob_end_clean(); return strlen($tmp) ? $tmp : true; } // Use a SMTP server directly instead $smtp = new smtp_class(); $smtp->host_name = $hesk_settings['smtp_host_name']; $smtp->host_port = $hesk_settings['smtp_host_port']; $smtp->timeout = $hesk_settings['smtp_timeout']; $smtp->ssl = $hesk_settings['smtp_ssl']; $smtp->start_tls = $hesk_settings['smtp_tls']; $smtp->user = $hesk_settings['smtp_user']; $smtp->password = hesk_htmlspecialchars_decode($hesk_settings['smtp_password']); $smtp->debug = 1; // Start output buffering so that any errors don't break headers ob_start(); // Send the e-mail using SMTP $to_arr = explode(',', $to); $headersArray = array("From: {$hesk_settings['from_header']}", "To: {$to}", "Reply-To: {$hesk_settings['from_header']}", "Return-Path: {$hesk_settings['webmaster_mail']}", "Subject: " . $subject, "Date: " . date(DATE_RFC2822)); array_push($headersArray, "MIME-Version: 1.0"); array_push($headersArray, "Content-Type: multipart/mixed;boundary=\"" . $outerboundary . "\""); if (count($cc) > 0) { array_push($headersArray, "Cc: " . implode(',', $cc)); } if (count($bcc) > 0) { array_push($headersArray, "Bcc: " . implode(',', $bcc)); } // Add attachments if necessary if ($hasMessageTag && $modsForHesk_settings['attachments'] && $hesk_settings['attachments']['use'] && isset($ticket['attachments']) && strlen($ticket['attachments'])) { $message .= processDirectAttachments('smtp', NULL, $outerboundary); } $message .= "\n\n" . '--' . $outerboundary . '--'; if (!$smtp->SendMessage($hesk_settings['noreply_mail'], $to_arr, $headersArray, $message)) { // Suppress errors unless we are in debug mode if ($hesk_settings['debug_mode']) { $error = $hesklang['cnsm'] . ' ' . $to . '<br /><br />' . $hesklang['error'] . ': ' . htmlspecialchars($smtp->error) . '<br /><br />' . '<textarea name="smtp_log" rows="10" cols="60">' . ob_get_contents() . '</textarea>'; ob_end_clean(); hesk_error($error); } else { $_SESSION['HESK_2ND_NOTICE'] = true; $_SESSION['HESK_2ND_MESSAGE'] = $hesklang['esf'] . ' ' . $hesklang['contact_webmsater'] . ' <a href="mailto:' . $hesk_settings['webmaster_mail'] . '">' . $hesk_settings['webmaster_mail'] . '</a>'; } } ob_end_clean(); return true; }
function hesk_mail($to, $subject, $message) { global $hesk_settings, $hesklang; // Demo mode if (defined('HESK_DEMO')) { return true; } // Encode subject to UTF-8 $subject = "=?UTF-8?B?" . base64_encode(hesk_html_entity_decode($subject)) . "?="; // Setup "name <email>" for headers if ($hesk_settings['noreply_name']) { $hesk_settings['from_header'] = "=?UTF-8?B?" . base64_encode(hesk_html_entity_decode($hesk_settings['noreply_name'])) . "?= <" . $hesk_settings['noreply_mail'] . ">"; } else { $hesk_settings['from_header'] = $hesk_settings['noreply_mail']; } // Uncomment for debugging # echo "<p>TO: $to<br >SUBJECT: $subject<br >MSG: $message</p>"; # return true; // Use PHP's mail function if (!$hesk_settings['smtp']) { // Set additional headers $headers = "From: {$hesk_settings['from_header']}\n"; $headers .= "Reply-To: {$hesk_settings['from_header']}\n"; $headers .= "Return-Path: {$hesk_settings['webmaster_mail']}\n"; $headers .= "Date: " . date(DATE_RFC2822) . "\n"; $headers .= "Content-Type: text/plain; charset=" . $hesklang['ENCODING']; // Send using PHP mail() function ob_start(); mail($to, $subject, $message, $headers); $tmp = trim(ob_get_contents()); ob_end_clean(); return strlen($tmp) ? $tmp : true; } // Use a SMTP server directly instead $smtp = new smtp_class(); $smtp->host_name = $hesk_settings['smtp_host_name']; $smtp->host_port = $hesk_settings['smtp_host_port']; $smtp->timeout = $hesk_settings['smtp_timeout']; $smtp->ssl = $hesk_settings['smtp_ssl']; $smtp->start_tls = $hesk_settings['smtp_tls']; $smtp->user = $hesk_settings['smtp_user']; $smtp->password = hesk_htmlspecialchars_decode($hesk_settings['smtp_password']); $smtp->debug = 1; // Start output buffering so that any errors don't break headers ob_start(); // Send the e-mail using SMTP $to_arr = explode(',', $to); if (!$smtp->SendMessage($hesk_settings['noreply_mail'], $to_arr, array("From: {$hesk_settings['from_header']}", "To: {$to}", "Reply-To: {$hesk_settings['from_header']}", "Return-Path: {$hesk_settings['webmaster_mail']}", "Subject: " . $subject, "Date: " . date(DATE_RFC2822), "Content-Type: text/plain; charset=" . $hesklang['ENCODING']), $message)) { // Suppress errors unless we are in debug mode if ($hesk_settings['debug_mode']) { $error = $hesklang['cnsm'] . ' ' . $to . '<br /><br />' . $hesklang['error'] . ': ' . htmlspecialchars($smtp->error) . '<br /><br />' . '<textarea name="smtp_log" rows="10" cols="60">' . ob_get_contents() . '</textarea>'; ob_end_clean(); hesk_error($error); } else { $_SESSION['HESK_2ND_NOTICE'] = true; $_SESSION['HESK_2ND_MESSAGE'] = $hesklang['esf'] . ' ' . $hesklang['contact_webmsater'] . ' <a href="mailto:' . $hesk_settings['webmaster_mail'] . '">' . $hesk_settings['webmaster_mail'] . '</a>'; } } ob_end_clean(); return true; }