nulib-base/php/tbin/sendmail.php

29 lines
982 B
PHP
Executable File

#!/usr/bin/php
<?php
require __DIR__.'/../vendor/autoload.php';
use nulib\app\cli\Application;
use nulib\cv;
use nulib\mail\mailer;
use nulib\ValueException;
Application::run(new class extends Application {
const ARGS = [
"usage" => "SUBJECT BODY -t RECIPIENT",
"merge" => parent::ARGS,
["-F", "--from", "args" => 1, "name" => "from", "argsdesc" => "MAILFROM"],
["-t", "--to", "args" => 1, "action" => "--add", "name" => "to", "argsdesc" => "RECIPIENT"],
["-c", "--cc", "args" => 1, "action" => "--add", "name" => "cc", "argsdesc" => "RECIPIENT"],
["-b", "--bcc", "args" => 1, "action" => "--add", "name" => "bcc", "argsdesc" => "RECIPIENT"],
["args" => 2, "name" => "args"],
];
protected $to, $cc, $bcc, $from;
function main() {
$subject = cv::not_null($this->args[0] ?? null, "subject");
$body = cv::not_null($this->args[1] ?? null, "body");
mailer::send($this->to, $subject, $body, $this->cc, $this->bcc, $this->from);
}
});