mailSendService = $mailSendService; } /** * コマンド実行 * * @return int */ public function handle() { // パラメータ取得 $email = $this->argument('email') ?? 'wyf_0506@hotmail.com'; $backupEmail = $this->option('backup') ?? ''; $templateId = (int) $this->option('template'); // 確認画面 $this->info('=== SHJ-7 メール送信テスト ==='); $this->line(''); $this->line("送信先メールアドレス: {$email}"); $this->line("予備メールアドレス : " . ($backupEmail ?: '(なし)')); $this->line("テンプレートID : {$templateId}"); $this->line(''); // 環境チェック $mailDriver = config('mail.default'); $this->warn("現在のメール設定: MAIL_MAILER={$mailDriver}"); if ($mailDriver === 'log') { $this->warn('⚠ メールはログファイルにのみ記録され、実際には送信されません'); $this->warn('⚠ 実際に送信するには .env で MAIL_MAILER=smtp 等に変更してください'); } else { $this->info("✓ メールは実際に送信されます({$mailDriver})"); } $this->line(''); // 実行確認 if (!$this->confirm('メール送信を実行しますか?', true)) { $this->info('キャンセルしました。'); return self::SUCCESS; } // メール送信実行 $this->line(''); $this->info('メール送信を開始します...'); try { $startTime = now(); // SHJ-7サービス呼び出し $result = $this->mailSendService->executeMailSend( $email, $backupEmail, $templateId ); $endTime = now(); $duration = $startTime->diffInSeconds($endTime); $this->line(''); $this->info('=== 実行結果 ==='); if ($result['result'] === 0) { $this->info('✓ メール送信成功'); $this->line("処理時間: {$duration}秒"); if ($mailDriver === 'log') { $this->line(''); $this->comment('※ ログファイルを確認してください:'); $this->comment(' storage/logs/laravel.log'); } else { $this->line(''); $this->comment("※ {$email} のメールボックスを確認してください"); } return self::SUCCESS; } else { $this->error('✗ メール送信失敗'); $this->error("エラー情報: {$result['error_info']}"); $this->line(''); $this->comment('ログファイルで詳細を確認してください: storage/logs/laravel.log'); return self::FAILURE; } } catch (\Exception $e) { $this->error('✗ 予期しないエラーが発生しました'); $this->error("エラー: {$e->getMessage()}"); Log::error('test:mail コマンドエラー', [ 'exception' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); return self::FAILURE; } } }