mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 17:29:21 +02:00
Add send_email bash command
Usage: echo message | php send_email.php account_name_or_id|player_name|email subject Real example: echo "Hello, this is my test email" | php send_email.php "God Slawkens" "Hello world E-Mail"
This commit is contained in:
parent
be9ce34dc8
commit
e8363d7310
55
system/bin/send_email.php
Normal file
55
system/bin/send_email.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
if(PHP_SAPI !== 'cli') {
|
||||
die('This script can be run only in command line mode.');
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../../common.php';
|
||||
require_once SYSTEM . 'functions.php';
|
||||
require_once SYSTEM . 'init.php';
|
||||
|
||||
if($argc !== 3) {
|
||||
exit('This command expects two parameters: account_name_or_id|player_name|email address, subject.' . PHP_EOL);
|
||||
}
|
||||
|
||||
$email_account_name = $argv[1];
|
||||
$subject = $argv[2];
|
||||
$message = file_get_contents('php://stdin');
|
||||
|
||||
if(strpos($email_account_name, '@') === false) {
|
||||
$account = new OTS_Account();
|
||||
if(USE_ACCOUNT_NAME) {
|
||||
$account->find($email_account_name);
|
||||
}
|
||||
else {
|
||||
$account->load($email_account_name);
|
||||
}
|
||||
|
||||
if($account->isLoaded()) {
|
||||
$email_account_name = $account->getEMail();
|
||||
}
|
||||
else {
|
||||
$player = new OTS_Player();
|
||||
$player->find($email_account_name);
|
||||
if($player->isLoaded()) {
|
||||
$email_account_name = $player->getAccount()->getEMail();
|
||||
}
|
||||
else {
|
||||
exit('Cannot find player or account with name: ' . $email_account_name . '.' . PHP_EOL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!Validator::email($email_account_name)) {
|
||||
exit('Invalid E-Mail format.' . PHP_EOL);
|
||||
}
|
||||
|
||||
if(strlen($subject) > 255) {
|
||||
exit('Subject max length is 255 characters.' . PHP_EOL);
|
||||
}
|
||||
|
||||
if(!_mail($email_account_name, $subject, $message)) {
|
||||
exit('Error while sending mail: ' . $mailer->ErrorInfo . PHP_EOL);
|
||||
}
|
||||
|
||||
echo 'Mail sent to ' . $email_account_name . '.' . PHP_EOL;
|
Loading…
x
Reference in New Issue
Block a user