Skip to content

Commit

Permalink
Merge pull request #246 from dbarzin/dev
Browse files Browse the repository at this point in the history
fix mail send
  • Loading branch information
dbarzin authored Jan 20, 2025
2 parents 6077b9f + 1561cec commit 8e16435
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 44 deletions.
76 changes: 38 additions & 38 deletions app/Console/Commands/SendNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,7 @@ public function handle()
' days.'
);

// Create a new PHPMailer instance
$mail = new PHPMailer(true);

try {
// Server settings
$mail->isSMTP(); // Use SMTP
$mail->Host = env('MAIL_HOST'); // Set the SMTP server
$mail->SMTPAuth = env('MAIL_AUTH'); // Enable SMTP authentication
$mail->Username = env('MAIL_USERNAME'); // SMTP username
$mail->Password = env('MAIL_PASSWORD'); // SMTP password
$mail->SMTPSecure = env('MAIL_SMTP_SECURE',false); // Enable TLS encryption, `ssl` also accepted
$mail->SMTPAutoTLS = env('MAIL_SMTP_AUTO_TLS'); // Enable auto TLS
$mail->Port = env('MAIL_PORT'); // TCP port to connect to

// Loop on all users
$users = User::all();

Expand All @@ -83,33 +70,46 @@ public function handle()
->orderBy('plan_date')
->get();

if ($controls->count() > 0) {
App::setlocale($user->language);
$txt = '';
foreach ($controls as $control) {
// Date
$txt .= '<a href="' . url('/bob/show/'. $control->id) . '">';
$txt .= '<b>';
if (strtotime($control->plan_date) >= strtotime('today')) {
$txt .= "<font color='green'>" . $control->plan_date .' </font>';
} else {
$txt .= "<font color='red'>" . $control->plan_date . '</font>';
}
$txt .= '</b>';
$txt .= '</a>';
if ($controls->count() > 0) {
App::setlocale($user->language);
$txt = '';
foreach ($controls as $control) {
// Date
$txt .= '<a href="' . url('/bob/show/'. $control->id) . '">';
$txt .= '<b>';
if (strtotime($control->plan_date) >= strtotime('today')) {
$txt .= "<font color='green'>" . $control->plan_date .' </font>';
} else {
$txt .= "<font color='red'>" . $control->plan_date . '</font>';
}
$txt .= '</b>';
$txt .= '</a>';
// Space
$txt .= ' &nbsp; - &nbsp; ';
// Clauses
foreach ($control->measures as $measure) {
$txt .= '<a href="' . url('/alice/show/' . $measure->id) . '">'. htmlentities($measure->clause) . '</a>';
// Space
$txt .= ' &nbsp; - &nbsp; ';
// Clauses
foreach ($control->measures as $measure) {
$txt .= '<a href="' . url('/alice/show/' . $measure->id) . '">'. htmlentities($measure->clause) . '</a>';
// Space
$txt .= ' &nbsp; ';
}
$txt .= ' - &nbsp; ';
// Name
$txt .= htmlentities($control->name);
$txt .= "<br>\n";
$txt .= ' &nbsp; ';
}
$txt .= ' - &nbsp; ';
// Name
$txt .= htmlentities($control->name);
$txt .= "<br>\n";
}

// Create a new PHPMailer instance
$mail = new PHPMailer(true);

// Server settings
$mail->isSMTP(); // Use SMTP
$mail->Host = env('MAIL_HOST'); // Set the SMTP server
$mail->SMTPAuth = env('MAIL_AUTH'); // Enable SMTP authentication
$mail->Username = env('MAIL_USERNAME'); // SMTP username
$mail->Password = env('MAIL_PASSWORD'); // SMTP password
$mail->SMTPSecure = env('MAIL_SMTP_SECURE',false); // Enable TLS encryption, `ssl` also accepted
$mail->SMTPAutoTLS = env('MAIL_SMTP_AUTO_TLS'); // Enable auto TLS
$mail->Port = env('MAIL_PORT'); // TCP port to connect to

// Recipients
$mail->setFrom(config('deming.notification.mail-from'));
Expand Down
16 changes: 10 additions & 6 deletions app/Http/Controllers/ConfigurationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public function save(Request $request)
{
abort_if(Auth::User()->role !== 1, Response::HTTP_FORBIDDEN, '403 Forbidden');

// Error and message variables
$error = null;
$message = null;

// read request
$mail_from = request('mail_from');
$mail_subject = request('mail_subject');
Expand All @@ -65,7 +69,7 @@ public function save(Request $request)
file_put_contents(config_path('deming.php'), $text);

// Return
$msg = 'Configuration saved !';
$message = 'Configuration saved !';
break;

case 'test':
Expand Down Expand Up @@ -105,9 +109,9 @@ public function save(Request $request)
// Send email
$mail->send();

$msg = 'Message has been sent';
$message = 'Message has been sent';
} catch (Exception $e) {
$msg = "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
$error = "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

break;
Expand All @@ -116,13 +120,13 @@ public function save(Request $request)
return redirect('/');

default:
$msg = 'No actions made.';
$message = 'No actions made.';
}

return view(
'config',
compact('mail_from', 'mail_subject', 'mail_content', 'frequency', 'expire_delay', 'reminder')
compact('mail_from', 'mail_subject', 'mail_content', 'frequency', 'expire_delay', 'reminder', 'message')
)
->withErrors($msg);
->withErrors($error);
}
}
10 changes: 10 additions & 0 deletions resources/views/config.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
</div>
@endif

@if ($message!=null)
<div class="form-group">
<div class= "remark success">
<ul>
{{ $message }}
</ul>
</div>
</div>
@endif

<form method="POST" action="/config/save" enctype="multipart/form-data">
@csrf

Expand Down

0 comments on commit 8e16435

Please sign in to comment.