1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
- $shortoptions = 'i:n:';
- $longoptions = array('id=', 'nickname=', 'subject=');
- $helptext = <<<END_OF_USEREMAIL_HELP
- sendemail.php [options] < <message body>
- Sends given email text to user.
- -i --id id of the user to query
- -n --nickname nickname of the user to query
- --subject mail subject line (required)
- END_OF_USEREMAIL_HELP;
- require_once INSTALLDIR.'/scripts/commandline.inc';
- if (have_option('i', 'id')) {
- $id = get_option_value('i', 'id');
- $user = User::getKV('id', $id);
- if (empty($user)) {
- print "Can't find user with ID $id\n";
- exit(1);
- }
- } else if (have_option('n', 'nickname')) {
- $nickname = get_option_value('n', 'nickname');
- $user = User::getKV('nickname', $nickname);
- if (empty($user)) {
- print "Can't find user with nickname '$nickname'\n";
- exit(1);
- }
- } else {
- print "You must provide a user by --id or --nickname\n";
- exit(1);
- }
- if (empty($user->email)) {
-
- print "No email registered for user '$user->nickname'\n";
- exit(1);
- }
- if (!have_option('subject')) {
- echo "You must provide a subject line for the mail in --subject='...' param.\n";
- exit(1);
- }
- $subject = get_option_value('subject');
- if (posix_isatty(STDIN)) {
- print "You must provide message input on stdin!\n";
- exit(1);
- }
- $body = file_get_contents('php://stdin');
- print "Sending to $user->email...";
- if (mail_to_user($user, $subject, $body)) {
- print " done\n";
- } else {
- print " failed.\n";
- exit(1);
- }
|