Skouter mortgage estimates. Web application with view written in PHP and Vue, but controller and models in Go.
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

TestEmailCommand.php 3.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace Grav\Plugin\Console;
  3. use Grav\Common\Grav;
  4. use Grav\Common\Data\Data;
  5. use Grav\Console\ConsoleCommand;
  6. use Grav\Plugin\Email\Email;
  7. use Grav\Plugin\Email\Utils as EmailUtils;
  8. use Symfony\Component\Console\Input\InputOption;
  9. /**
  10. * Class TestEmailCommand
  11. * @package Grav\Console\Cli\
  12. */
  13. class TestEmailCommand extends ConsoleCommand
  14. {
  15. /** @var array */
  16. protected $options = [];
  17. /**
  18. * @return void
  19. */
  20. protected function configure()
  21. {
  22. $this
  23. ->setName('test-email')
  24. ->setAliases(['testemail'])
  25. ->addOption(
  26. 'to',
  27. 't',
  28. InputOption::VALUE_REQUIRED,
  29. 'An email address to send the email to'
  30. )
  31. ->addOption(
  32. 'env',
  33. 'e',
  34. InputOption::VALUE_OPTIONAL,
  35. 'The environment to trigger a specific configuration. For example: localhost, mysite.dev, www.mysite.com'
  36. )
  37. ->addOption(
  38. 'subject',
  39. 's',
  40. InputOption::VALUE_OPTIONAL,
  41. 'A subject for the email'
  42. )
  43. ->addOption(
  44. 'body',
  45. 'b',
  46. InputOption::VALUE_OPTIONAL,
  47. 'The body of the email'
  48. )
  49. ->setDescription('Sends a test email using the plugin\'s configuration')
  50. ->setHelp('The <info>test-email</info> command sends a test email using the plugin\'s configuration');
  51. }
  52. /**
  53. * @return int
  54. */
  55. protected function serve()
  56. {
  57. // TODO: remove when requiring Grav 1.7+
  58. if (method_exists($this, 'initializeGrav')) {
  59. $this->initializeThemes();
  60. }
  61. $this->output->writeln('');
  62. $this->output->writeln('<yellow>Current Configuration:</yellow>');
  63. $this->output->writeln('');
  64. $grav = Grav::instance();
  65. $email_config = new Data($grav['config']->get('plugins.email'));
  66. if ($email_config->get('mailer.smtp.password')) {
  67. $password = $email_config->get('mailer.smtp.password');
  68. $obfuscated_password = str_repeat('*', strlen($password) - 2) . substr($password, -2);
  69. $email_config->set('mailer.smtp.password', $obfuscated_password);
  70. }
  71. dump($email_config);
  72. $this->output->writeln('');
  73. $to = $this->input->getOption('to') ?: $grav['config']->get('plugins.email.to');
  74. $subject = $this->input->getOption('subject');
  75. $body = $this->input->getOption('body');
  76. if (!$subject) {
  77. $subject = 'Testing Grav Email Plugin';
  78. }
  79. if (!$body) {
  80. $configuration = print_r($email_config, true);
  81. $body = $grav['language']->translate(['PLUGIN_EMAIL.TEST_EMAIL_BODY', $configuration]);
  82. }
  83. $sent = EmailUtils::sendEmail(['subject'=>$subject, 'body'=>$body, 'to'=>$to]);
  84. if ($sent) {
  85. $this->output->writeln("<green>Message sent successfully!</green>");
  86. } else {
  87. $this->output->writeln("<red>Problem sending email...</red>");
  88. }
  89. return 0;
  90. }
  91. }