File manager - Edit - /var/www/payraty/hris-standalone/app/Console/Commands/SendEmployeeEmails.php
Back
<?php namespace App\Console\Commands; use App\Models\User; use Illuminate\Console\Command; use Illuminate\Support\Facades\DB; class SendEmployeeEmails extends Command { protected $signature = 'email:send-employees'; protected $description = 'Send welcome email to all employees using Postmark template'; public function handle() { $employees = User::where('type', 'employee')->all(); // DB::table('employees')->get(); foreach ($employees as $employee) { $payload = [ "From" => "info@payraty.com", "To" => $employee->email, "TemplateAlias" => "Welcome to Payraty(hris)", "TemplateModel" => [ "product_url" => "https://payraty.com", "product_name" => "Payraty", "name" => $employee->name, "action_url" => "https://hris.payraty.com/", "login_url" => "https://hris.payraty.com/", "username" => $employee->email, "password" => "1234", "company_name" => "Payraty", "company_address" => "" ] ]; $response = $this->sendPostmarkEmail($payload); if ($response['success']) { $this->info("✅ Email sent to {$employee->email}"); } else { $this->error("❌ Failed to send to {$employee->email}: {$response['error']}"); } } } private function sendPostmarkEmail($payload) { $ch = curl_init('https://api.postmarkapp.com/email/withTemplate'); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Accept: application/json', 'Content-Type: application/json', 'X-Postmark-Server-Token: 07351fe9-b47f-4194-9dcc-dae0e04109b0' ]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); curl_setopt($ch, CURLOPT_POST, true); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if (curl_errno($ch)) { $error = curl_error($ch); curl_close($ch); return ['success' => false, 'error' => $error]; } curl_close($ch); if ($httpCode === 200) { return ['success' => true]; } else { return ['success' => false, 'error' => $response]; } } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.30 | Generation time: 0.69 |
proxy
|
phpinfo
|
Settings