/* Purpose: - set 'text/plain' and 'text/html' version of message - send mail directly to client (without MTA support) - add attachment - embed image into HTML - print result */ // manage errors error_reporting(E_ALL); // php errors define('DISPLAY_XPM4_ERRORS', true); // display XPM4 errors // path to 'MAIL.php' file from XPM4 package require_once '../MAIL.php'; // get ID value (random) for the embed image $id = MIME::unique(); // initialize MAIL class $m = new MAIL(); // set from address and name $m->From('*****@*****.**', 'My Name'); // add to address and name $m->AddTo('*****@*****.**', 'Client Name'); // set subject $m->Subject('Hello World!'); // set text/plain version of message $m->Text('Text version of message.'); // set text/html version of message $m->Html('<b>HTML</b> version of <u>message</u>.<br><i>Powered by</i> <img src="cid:' . $id . '">'); // add attachment ('text/plain' file) $m->Attach('source file', 'text/plain'); $f = 'xpertmailer.gif';
function nulluhr() { global $db; update_all_ranks(); $db->query('DELETE FROM ' . DB_PRE . 'ecp_messages WHERE fromdel = 1 AND del = 1'); $result = $db->query('SELECT ID FROM ' . DB_PRE . 'ecp_user WHERE (ondelete < ' . time() . ' AND ondelete != 0) OR (status = 0 AND registerdate < ' . (time() - DELETE_UNAKTIV * 86400) . ')'); while ($row = mysql_fetch_assoc($result)) { delete_user($row['ID']); } $result = $db->query('SELECT ID, money FROM ' . DB_PRE . 'ecp_user LEFT JOIN ' . DB_PRE . 'ecp_ranks ON (rID = rankID)'); while ($row = mysql_fetch_assoc($result)) { if ($row['money'] != '') { $db->query('UPDATE ' . DB_PRE . 'ecp_user_stats SET money = money + ' . $row['money'] . ' WHERE userID = ' . $row['ID']); } } if (BACKUP_AKTIV) { $last = $db->result(DB_PRE . 'ecp_stats', 'lastdbbackup', '1'); if (BACKUP_CYCLE == 'day' or $last + (BACKUP_CYCLE == 'month' ? 2592000 : 604800) < time()) { $backup_obj = new MySQL_Backup(); $backup_obj->server = MYSQL_HOST; $backup_obj->username = MYSQL_USER; $backup_obj->password = MYSQL_PASS; $backup_obj->database = MYSQL_DATABASE; $backup_obj->tables = array(); $backup_obj->drop_tables = true; $backup_obj->struct_only = false; $backup_obj->comments = true; $backup_obj->fname_format = 'd_m_y__H_i_s'; $string = get_random_string(8, 2); if ($backup_obj->Execute(MSB_SAVE, 'uploads/forum/' . $string . '.sql.gz', true)) { $m = new XMail(); // set from address and name $m->From(SITE_EMAIL); // add to address and name $m->AddTo(BACKUP_EMAIL); // set subject $m->Subject(BACKUP_AUTO); // set text/plain version of message $m->Text(DATE . ': ' . date('d.m.Y H:i:s')); // add attachment ('text/plain' file) $m->Attach(date('Y_m_d') . '.sql.gz', 'application/x-gzip'); $f = 'uploads/forum/' . $string . '.sql.gz'; $id = MIME::unique(); // add inline attachment '$f' file with ID '$id' $m->Attach(file_get_contents($f), FUNC::mime_type($f), null, null, null, 'attachment', $id); if (SMTP_AKTIV) { $c = $m->Connect(SMTP_HOST, (int) SMTP_PORT, SMTP_USER, SMTP_PASS, 'tls', 10, 'localhost', null, 'plain'); //or die(print_r($m->Result)); } if ($m->Send(SMTP_AKTIV ? $c : null)) { $db->query('UPDATE ' . DB_PRE . 'ecp_stats SET lastdbbackup = ' . strtotime('today 00:00:00')); } unlink('uploads/forum/' . $string . '.sql.gz'); } } } $result = $db->query('SELECT attachID, strname FROM ' . DB_PRE . 'ecp_forum_attachments WHERE (tID = 0 OR bID = 0) AND uploadzeit < ' . (time() - 1000)); while ($row = $db->fetch_assoc()) { @unlink('upload/forum/' . $row['attachID'] . '_' . $row['strname']); } $db->query('DELETE FROM ' . DB_PRE . 'ecp_forum_attachments WHERE (tID = 0 OR bID = 0) AND uploadzeit < ' . (time() - 1000)); // Buchungen durchf�hren $buchresult = $db->query('SELECT `ID`, `verwendung`, `intervall`, `betrag`, `nextbuch`, `tagmonat` FROM ' . DB_PRE . 'ecp_clankasse_auto WHERE nextbuch <= \'' . time() . '\''); while ($row = mysql_fetch_assoc($buchresult)) { $db->query('INSERT INTO ' . DB_PRE . 'ecp_clankasse_transaktion (`geld`, `verwendung`, `datum`, `userID`) VALUES (-' . $row['betrag'] . ', \'' . mysql_real_escape_string($row['verwendung']) . '\', ' . time() . ', 0)'); $db->query('UPDATE ' . DB_PRE . 'ecp_clankasse SET kontostand = kontostand - ' . $row['betrag']); switch ($row['tagmonat']) { case 1: $nextdate = strtotime('+ ' . (int) $row['intervall'] . ' month'); break; case 15: $nextdate = strtotime('+ ' . (int) $row['intervall'] . ' month'); break; case 28: $nextdate = strtotime('+ ' . (int) $row['intervall'] . ' month'); } $db->query('UPDATE ' . DB_PRE . 'ecp_clankasse_auto SET `nextbuch` = \'' . $nextdate . '\''); } $db->query('DELETE FROM ' . DB_PRE . 'ecp_forum_search WHERE datum < ' . (time() - 86400)); $result = $db->query('SELECT COUNT(sID) as anzahl, sID FROM ' . DB_PRE . 'ecp_server_stats GROUP BY sID'); while ($row = mysql_fetch_assoc($result)) { if ($row['anzahl'] > SERVER_MAX_LOG) { $db->query('DELETE FROM ' . DB_PRE . 'ecp_server_stats WHERE sID = ' . $row['sID'] . ' ORDER BY datum ASC LIMIT ' . ($row['anzahl'] - SERVER_MAX_LOG)); } } }
/** * Sends the email specified by $emailId to all recipients. * @param integer $emailId The id of the email message. * @param string $emailTable Optional the name of the table containing the email messages. * @param string $joinTable Optional the name of the table corresponding to a single recipient of the given email. * @param string $recipientsTable The name of the table where the recipients originated from. * @param string $emailColumn The name of the column that stored the email address. */ function sendMail($emailId, $emailTable = null, $joinTable = null, $recipientsTable = null, $emailColumn = null) { require_once dirname(__FILE__) . '/../lib/XPM/MIME.php'; if (isset($emailTable)) { $this->emailTable = $emailTable; } if (isset($joinTable)) { $this->joinTable = $joinTable; } if (isset($recipientsTable)) { $this->recipientsTable = $recipientsTable; } if (isset($emailColumn)) { $this->emailColumn = $emailColumn; } $app =& Dataface_Application::getInstance(); $conf =& $app->_conf; if (@$conf['_mail']['func']) { $mail_func = $conf['_mail']['func']; } else { $mail_func = 'mail'; } $emailTableObj =& Dataface_Table::loadTable($this->emailTable); $emailTableObj->addRelationship('recipients', array('__sql__' => 'select * from `' . $this->recipientsTable . '` r inner join `' . $this->joinTable . '` j on `r`.`' . $this->emailColumn . '` = j.recipient_email inner join `' . $this->emailTable . '` e on e.id = j.messageid where e.id=\'' . addslashes($emailId) . '\'')); $email = df_get_record($this->emailTable, array('id' => $emailId)); if (!$email) { return PEAR::raiseError("Failed to send email because no message with id {$emailId} could be found.", DATAFACE_E_ERROR); } $recipients = $email->getRelatedRecordObjects('recipients', 0, 500, 'sent=0'); foreach ($recipients as $recipient) { $values = $recipient->strvals(); $keys = array(); foreach ($values as $key => $val) { $keys[] = '/%' . $key . '%/'; } $values = array_values($values); $content = preg_replace($keys, $values, $recipient->strval('content')); $opt_out_url = df_absolute_url(DATAFACE_SITE_HREF . '?-action=email_opt_out&email=' . urlencode($recipient->val('recipient_email'))); $html_content = $content .= <<<END \t\t\t<hr /> <p>If you don't want to receive email updates from us, you can opt out of our mailing list by clicking <a href="{$opt_out_url}">here</a> .</p> END; $content .= <<<END ------------------------------------------------------------------ If you don't want to receive email updates from us, you can opt out of our mailing list by going to {$opt_out_url} . END; $headers = array(); if ($email->strval('from')) { $headers[] = "From: " . $email->strval('from'); $headers[] = "Reply-to: " . $email->strval('from'); } if (@$app->_conf['mail_host']) { $headers[] = 'Message-ID: <' . md5(uniqid(time())) . '@' . $app->_conf['mail_host'] . '>'; } //$headers[] = "Content-Type: text/plain; charset=".$app->_conf['oe']; $joinRecord = $recipient->toRecord($this->joinTable); if (!trim($recipient->val('recipient_email'))) { $joinRecord->setValue('success', 0); $joinRecord->setValue('sent', 1); $joinRecord->save(); unset($joinRecord); unset($recipient); continue; } // path to 'MIME.php' file from XPM4 package // get ID value (random) for the embed image $id = MIME::unique(); // set text/plain version of message $text = MIME::message(htmlspecialchars_decode(strip_tags(preg_replace(array('/<br[^>]*>/i', '/<div[^>]*>/i', '/<p[^>]*>/i', '/<table[^>]*>/i'), array("\r\n", "\r\n", "\r\n", "\r\n"), $content))), 'text/plain'); // set text/html version of message $html = MIME::message($html_content, 'text/html'); // add attachment with name 'file.txt' //$at[] = MIME::message('source file', 'text/plain', 'file.txt', 'ISO-8859-1', 'base64', 'attachment'); //$file = 'xpertmailer.gif'; // add inline attachment '$file' with name 'XPM.gif' and ID '$id' //$at[] = MIME::message(file_get_contents($file), FUNC::mime_type($file), 'XPM.gif', null, 'base64', 'inline', $id); // compose mail message in MIME format $mess = MIME::compose($text, $html); if (!$email->val('ignore_blacklist') and $this->isBlackListed($recipient->val('recipient_email'))) { echo "\nEmail address '" . $recipient->val('recipient_email') . "' is black listed so we do not send email to this address..."; $joinRecord->setValue('success', 0); $joinRecord->setValue('sent', 1); } else { if ($mail_func($recipient->strval('recipient_email'), $email->strval('subject'), $mess['content'], implode("\r\n", $headers) . "\r\n" . $mess['header'])) { $joinRecord->setValue('success', 1); $joinRecord->setValue('sent', 1); echo "Successfully sent email to " . $recipient->val('recipient_email'); //echo "Successfully sent email to {$recipient->strval('recipient_email')}" ; //exit; } else { $joinRecord->setValue('success', 0); $joinRecord->setValue('sent', 1); $this->messages[] = "Failed to send email to " . $email->val('recipient_email'); //echo "Failed to send"; //exit; } } $joinRecord->setValue('date_sent', date('Y-m-d H:i:s')); $joinRecord->save(); unset($joinRecord); unset($recipient); } }