fix(email send driver): use Command Utility to run command

This commit is contained in:
cubic
2023-02-13 15:13:18 +08:00
parent 253b1fcfe3
commit ab2b675247

View File

@@ -2,6 +2,7 @@
namespace service\MessageService\Email\Driver;
use service\Utility\Logger;
use service\Utility\Command;
class Mail {
static function send (string $to, string $title, string $body)
@@ -13,7 +14,17 @@ class Mail {
$from = YAML_EMAIL_NAME . '<' . YAML_EMAIL_FROM . '>';
$result = exec("export LANG=en_US.UTF-8 && echo -e '{$body}' | mail -r '{$from}' -s '{$title}' '{$to}' > /dev/null &");
// $result = exec("export LANG=en_US.UTF-8 && echo -e '{$body}' | mail -r '{$from}' -s '{$title}' '{$to}' > /dev/null &");
$result = [];
Command::run([
'echo', '-e', Command::wrapArgument($body), '|',
'mail', '-r', Command::wrapArgument($from),
'-s', Command::wrapArgument($title), Command::wrapArgument($to),
'> /dev/null &'
], $result);
$result = implode('', $result);
Logger::Log(
'from:' . $from . ' Sent result:' . json_encode($result),