Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tarea #3604 - Comprobar mailer del servidor #1647

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Core/Controller/ConfigEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ protected function loadData($viewName, $view)
case 'ConfigEmail':
$view->loadData('email');
$view->model->name = 'email';
$this->loadMailerValues($viewName);
if ($view->model->mailer === 'smtp') {
// añadimos el botón test
$this->addButton($viewName, [
Expand All @@ -197,6 +198,14 @@ protected function loadData($viewName, $view)
}
}

protected function loadMailerValues(string $viewName)
{
$column = $this->views[$viewName]->columnForName('mailer');
if ($column && $column->widget->getType() === 'select') {
$column->widget->setValuesFromArray(NewMail::getMailer(), true, false);
}
}

protected function testMailAction(): void
{
// guardamos los datos del formulario primero
Expand Down
25 changes: 25 additions & 0 deletions Core/Lib/Email/NewMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class NewMail
/** @var PHPMailer */
protected $mail;

/** @var array */
private static $mailer = ['mail' => 'Mail', 'sendmail' => 'SendMail', 'smtp' => 'SMTP'];

/** @var BaseBlock[] */
protected $mainBlocks = [];

Expand Down Expand Up @@ -123,6 +126,15 @@ public function __construct()
$this->verificode = Tools::randomString(20);
}

public static function addMailer(string $key, string $name): void
{
if (array_key_exists($key, self::$mailer)) {
return;
}

self::$mailer[$key] = $name;
}

/**
* @deprecated since version 2023.09
*/
Expand Down Expand Up @@ -276,6 +288,19 @@ public function getCCAddresses(): array
return $addresses;
}

public static function getMailer(): array
{
if (false === function_exists('mail')) {
unset(self::$mailer['mail']);
}

if (false === ini_get('sendmail_path')) {
unset(self::$mailer['sendmail']);
}

return self::$mailer;
}

public static function getTemplate(): string
{
return static::$template;
Expand Down
4 changes: 1 addition & 3 deletions Core/XMLView/ConfigEmail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@
</column>
<column name="mailer" numcolumns="3" order="140">
<widget type="select" fieldname="mailer" required="true">
<values title="Mail">mail</values>
<values title="SendMail">sendmail</values>
<values title="SMTP">smtp</values>
<values/>
</widget>
</column>
<column name="authentication" numcolumns="3" order="150">
Expand Down