4 * GNU social - a federating social network
6 * LICENCE: This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * @copyright 2008 Free Software Foundation http://fsf.org
22 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
23 * @link https://www.gnu.org/software/social/
26 define('INSTALLDIR', dirname(__DIR__));
27 define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
29 $shortoptions = 'i:n:a:';
30 $longoptions = ['id=', 'nickname=', 'subject=', 'all='];
32 $helptext = <<<END_OF_USEREMAIL_HELP
33 sendemail.php [options] < <message body>
34 Sends given email text to user.
36 -i --id id of the user to query
37 -a --all send to all users
38 -n --nickname nickname of the user to query
39 --subject mail subject line (required)
41 END_OF_USEREMAIL_HELP;
43 require_once INSTALLDIR.'/scripts/commandline.inc';
45 $all = have_option('a', 'all');
50 } else if (have_option('i', 'id')) {
51 $id = get_option_value('i', 'id');
52 $user = User::getKV('id', $id);
54 print "Can't find user with ID $id\n";
58 } else if (have_option('n', 'nickname')) {
59 $nickname = get_option_value('n', 'nickname');
60 $user = User::getKV('nickname', $nickname);
62 print "Can't find user with nickname '$nickname'.\n";
67 print "You must provide a user by --id, --nickname or just send something to --all\n";
71 if (!have_option('subject')) {
72 echo "You must provide a subject line for the mail in --subject='...' param.\n";
75 $subject = get_option_value('subject');
77 if (posix_isatty(STDIN)) {
78 print "You must provide message input on stdin!\n";
81 $body = file_get_contents('php://stdin');
84 while ($user->fetch()) {
85 _send($user, $subject, $body);
88 _send($user, $subject, $body);
91 function _send($user, $subject, $body) {
92 if (empty($user->email)) {
93 // @fixme unconfirmed address?
94 print "No email registered for user '$user->nickname'.\n";
97 print "Sending to $user->email... ";
98 if (mail_to_user($user, $subject, $body)) {