function sendMail($subject, $message, $emlList, $senderId = 0) { global $set, $rxEmailX; if ($senderId) { //sender is user $rSet = dbQuery("SELECT user_name, email FROM [db]users WHERE user_id = {$senderId} limit 1"); $row = mysql_fetch_assoc($rSet); $from = '"' . stripslashes($row['user_name']) . '" <' . stripslashes($row['email']) . '>'; } else { //sender is calendar $from = '"' . translit($set['calendarTitle'], true) . '" <' . $set['calendarEmail'] . '>'; } $notArray = explode(";", $emlList); $emlArray = array(); foreach ($notArray as $emlAorL) { //create email address list if (strpos($emlAorL, '@')) { //email address $emlArray[] = $emlAorL; } else { //email list $emlAorL .= strpos($emlAorL, '.') ? '' : '.txt'; if (file_exists("./emlists/{$emlAorL}")) { $emlArray = array_merge($emlArray, file("./emlists/{$emlAorL}", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)); } } } $recipList = ''; foreach ($emlArray as $emlAddress) { //create recipients list $emlAddress = trim($emlAddress); if (preg_match($rxEmailX, $emlAddress)) { //valid email address $recipList .= ', ' . $emlAddress; } } $recipList = ltrim($recipList, ' ,'); if ($set['mailServer'] == 1) { //mail via PHP $headers = 'MIME-Version: 1.0' . "\n" . 'Content-type: text/html; charset=utf-8' . "\n" . 'From: ' . $from; if (!mail($recipList, $subject, $message, $headers)) { //send PHP mail logError('luxcal', "PHP mail to {$recipList} failed."); return false; } // echo "Summary email sent.<br>Subject: {$subject}<br>Message: {$message}<br> To: {$recipList}<br><br>"; //test } elseif ($set['mailServer'] == 2) { //mail via SMTP server $headers = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=utf-8'; if (!smtpMail($from, $recipList, $subject, $message, $headers)) { // send SMTP mail return false; } } return '- ' . str_replace("@", "[at]", $recipList); }
function sendMail($subject, $message, $emlList, $senderId = 0) { global $set, $rxEmailX; if ($senderId) { //sender is user $stH = stPrep("SELECT `name`, `email` FROM `users` WHERE `ID` = ? limit 1"); stExec($stH, array($senderId)); list($name, $email) = $stH->fetch(PDO::FETCH_NUM); $from = "\"{$name}\" <{$email}>"; } else { //sender is calendar $from = '"' . translit($set['calendarTitle'], true) . '" <' . $set['calendarEmail'] . '>'; } $notArray = explode(";", $emlList); $emlArray = array(); foreach ($notArray as $emlAorL) { //create email address list if (strpos($emlAorL, '@')) { //email address $emlArray[] = $emlAorL; } else { //email list $emlAorL .= strpos($emlAorL, '.') ? '' : '.txt'; if (file_exists("./emlists/{$emlAorL}")) { $emlArray = array_merge($emlArray, file("./emlists/{$emlAorL}", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)); } } } $recipList = ''; foreach ($emlArray as $emlAddress) { //create recipients list $emlAddress = trim($emlAddress); if (preg_match($rxEmailX, $emlAddress)) { //valid email address $recipList .= ', ' . $emlAddress; } } $recipList = ltrim($recipList, ' ,'); $subject = '=?utf-8?B?' . base64_encode(htmlspecialchars_decode($subject, ENT_QUOTES)) . '?='; //follow RFC 1342 for utf-8 encoding if ($set['mailServer'] <= 1) { //mail via PHP $headers = "MIME-Version: 1.0\nContent-type: text/html; charset=utf-8\nFrom: {$from}\nBcc: {$recipList}\nDate: " . date(DATE_RFC2822); if (!mail(null, $subject, $message, $headers)) { //send PHP mail logMessage('luxcal', "PHP mail to {$recipList} failed.", true); return false; } // logMessage('luxcal',"PHP mail sent . . .\n- To: ".strip_tags("{$recipList}\n- Subject: {$subject} \n- Message: {$message}"),true); //TEST } elseif ($set['mailServer'] == 2) { //mail via SMTP server $headers = "MIME-Version: 1.0\nContent-type: text/html; charset=utf-8\nDate: " . date(DATE_RFC2822); if (!smtpMail($from, $recipList, $subject, $message, $headers)) { // send SMTP mail return false; } // logMessage('luxcal',"SMTP mail sent . . .\n- To: ".strip_tags("{$recipList}\n- Subject: {$subject} \n- Message: {$message}"),true); //TEST } return '- ' . str_replace("@", "[at]", $recipList); }