From a89311235c1fab36fda167f69f5f814e84a5f1c6 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 26 Aug 2007 11:32:48 +0100 Subject: improve digest sending (closes #138) --- functions.php | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) (limited to 'functions.php') diff --git a/functions.php b/functions.php index d82cb38ea..e2915aa00 100644 --- a/functions.php +++ b/functions.php @@ -61,6 +61,8 @@ require_once 'errors.php'; require_once 'version.php'; + require_once 'phpmailer/class.phpmailer.php'; + define('MAGPIE_USER_AGENT_EXT', ' (Tiny Tiny RSS/' . VERSION . ')'); define('MAGPIE_OUTPUT_ENCODING', 'UTF-8'); @@ -3156,12 +3158,42 @@ $headlines_count = $tuple[1]; if ($headlines_count > 0) { - $rc = mail($line["login"] . " <" . $line["email"] . ">", - "[tt-rss] New headlines for last 24 hours", $digest, - "From: " . MAIL_FROM . "\n". - "Content-Type: text/plain; charset=\"utf-8\"\n". - "Content-Transfer-Encoding: 8bit\n"); + + if (!DIGEST_SMTP_HOST) { + + $rc = mail($line["login"] . " <" . $line["email"] . ">", + "[tt-rss] New headlines for last 24 hours", $digest, + "From: " . DIGEST_FROM_NAME . " <" . DIGEST_FROM_ADDRESS . ">\n". + "Content-Type: text/plain; charset=\"utf-8\"\n". + "Content-Transfer-Encoding: 8bit\n"); + + } else { + + $mail = new PHPMailer(); + + $mail->PluginDir = "phpmailer/"; + $mail->SetLanguage("en", "phpmailer/language/"); + + $mail->From = DIGEST_FROM_ADDRESS; + $mail->FromName = DIGEST_FROM_NAME; + $mail->AddAddress($line["email"], $line["login"]); + $mail->Host = DIGEST_SMTP_HOST; + $mail->Mailer = "smtp"; + + $mail->Username = DIGEST_SMTP_LOGIN; + $mail->Password = DIGEST_SMTP_PASSWORD; + + $mail->Subject = "[tt-rss] New headlines for last 24 hours"; + $mail->Body = $digest; + + $rc = $mail->Send(); + + if (!$rc) print "ERROR: " . $mail->ErrorInfo; + + } + print "RC=$rc\n"; + db_query($link, "UPDATE ttrss_users SET last_digest_sent = NOW() WHERE id = " . $line["id"]); } else { @@ -3195,6 +3227,7 @@ ref_id = ttrss_entries.id AND feed_id = ttrss_feeds.id AND include_in_digest = true AND $interval_query + AND hidden = false AND ttrss_user_entries.owner_uid = $user_id AND unread = true ORDER BY ttrss_feeds.title, date_entered DESC LIMIT $limit"); -- cgit v1.2.3