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

Dev: update shield:setup command for set config/Emal::$mailType With html #1018

Closed
datamweb opened this issue Feb 8, 2024 · 0 comments · Fixed by #1020
Closed

Dev: update shield:setup command for set config/Emal::$mailType With html #1018

datamweb opened this issue Feb 8, 2024 · 0 comments · Fixed by #1020
Labels

Comments

@datamweb
Copy link
Collaborator

datamweb commented Feb 8, 2024

Shield uses html format to send emails. Therefore, it is better for command Setup to perform the settings related to public string $mailType = 'html';.

private function setupEmail(): void
{
$file = 'Config/Email.php';
$path = $this->distPath . $file;
$cleanPath = clean_path($path);
if (! is_file($path)) {
$this->error(" Not found file '{$cleanPath}'.");
return;
}
$config = config(EmailConfig::class);
$fromEmail = (string) $config->fromEmail; // Old Config may return null.
$fromName = (string) $config->fromName;
if ($fromEmail !== '' && $fromName !== '') {
$this->write(CLI::color(' Email Setup: ', 'green') . 'Everything is fine.');
return;
}
$content = file_get_contents($path);
$output = $content;
if ($fromEmail === '') {
$set = $this->prompt(' The required Config\Email::$fromEmail is not set. Do you set now?', ['y', 'n']);
if ($set === 'y') {
// Input from email
$fromEmail = $this->prompt(' What is your email?', null, 'required|valid_email');
$pattern = '/^ public .*\$fromEmail\s+= \'\';/mu';
$replace = ' public string $fromEmail = \'' . $fromEmail . '\';';
$output = preg_replace($pattern, $replace, $content);
}
}
if ($fromName === '') {
$set = $this->prompt(' The required Config\Email::$fromName is not set. Do you set now?', ['y', 'n']);
if ($set === 'y') {
$fromName = $this->prompt(' What is your name?', null, 'required');
$pattern = '/^ public .*\$fromName\s+= \'\';/mu';
$replace = ' public string $fromName = \'' . $fromName . '\';';
$output = preg_replace($pattern, $replace, $output);
}
}
if (write_file($path, $output)) {
$this->write(CLI::color(' Updated: ', 'green') . $cleanPath);
} else {
$this->error(" Error updating file '{$cleanPath}'.");
}
}

more info see https://forum.codeigniter.com/showthread.php?tid=89321

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant