From 14b9c76f64160687008308223b0142696f7016c1 Mon Sep 17 00:00:00 2001 From: Alexander Yakovlev Date: Thu, 4 May 2017 14:26:31 +0700 Subject: [PATCH] SMTP mailing --- composer.json | 1 + composer.lock | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ digest.php | 28 +++++++++++++++++++- 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 composer.lock diff --git a/composer.json b/composer.json index d41c28a..100765e 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,6 @@ { "minimum-stability": "dev", "require": { + "swiftmailer/swiftmailer": "^5.4" } } diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..7875adb --- /dev/null +++ b/composer.lock @@ -0,0 +1,73 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "49673bcd5268eaad7d3ebb1abf627a5b", + "content-hash": "8bfc43134a045ff6c4df3097bc1ea9fb", + "packages": [ + { + "name": "swiftmailer/swiftmailer", + "version": "5.x-dev", + "source": { + "type": "git", + "url": "https://github.com/swiftmailer/swiftmailer.git", + "reference": "cd4ffa87f4902527b1725587d368062c28eb98c2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/cd4ffa87f4902527b1725587d368062c28eb98c2", + "reference": "cd4ffa87f4902527b1725587d368062c28eb98c2", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "mockery/mockery": "~0.9.1", + "symfony/phpunit-bridge": "~3.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.4-dev" + } + }, + "autoload": { + "files": [ + "lib/swift_required.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Chris Corbyn" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Swiftmailer, free feature-rich PHP mailer", + "homepage": "http://swiftmailer.org", + "keywords": [ + "email", + "mail", + "mailer" + ], + "time": "2017-05-01 15:54:38" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/digest.php b/digest.php index 78b317d..a386631 100644 --- a/digest.php +++ b/digest.php @@ -16,7 +16,33 @@ WHERE usergroup = 4 AND isSubscribed = 1"); $users->execute(); $users = $users->fetchAll(); + +$url = $pdo->prepare("SELECT value FROM ".MYBB_PREFIX."settings WHERE name = 'bburl'"); +$url->execute(); +$url = $url->fetch()['value']; + +$tmp = $pdo->prepare("SELECT name, value FROM ".MYBB_PREFIX."settings WHERE name LIKE 'smtp_%'"); +$tmp->execute(); +$tmp = $tmp->fetchAll(); +$smtp = []; +foreach ($tmp as $row) { + $smtp[$row['name']] = $row['value']; +} +unset($tmp); +$transport = Swift_SmtpTransport::newInstance($smtp['smtp_host'], $smtp['smtp_port']) + ->setUsername($smtp['smtp_user']) + ->setPassword($smtp['smtp_password']); +$mailer = Swift_Mailer::newInstance($transport); + foreach ($users as $user) { $email = $user['email']; - print_email($user['username'], '/unsubscribe', $threads); + ob_start(); + print_email($user['username'], $url.'/unsubscribe', $threads); + $message = ob_end_flush(); + $message = Swift_Message::newInstance() + ->setSubject('Daily digest') + ->setFrom(array('john@doe.com' => 'John Doe')) + ->setTo(array($email => $user['username'])) + ->setBody($message, 'text/html'); + $mailer->send($message); }