penawaran = $penawaran; $this->permohonan = $permohonan; $this->villages = $villages; $this->districts = $districts; $this->cities = $cities; $this->provinces = $provinces; $this->user = $user; } /** * Build the message. */ public function buildHtml(): string { // Gunakan view test untuk testing atau view asli untuk produksi $viewName = 'emails.test-penawaran-tender-phpmailer'; // Cek apakah data berbentuk array atau object untuk menentukan view yang digunakan if (is_array($this->penawaran) || is_object($this->penawaran)) { // Gunakan view test untuk testing return view($viewName, [ 'penawaran' => $this->penawaran, 'permohonan' => $this->permohonan, 'villages' => $this->villages, 'districts' => $this->districts, 'cities' => $this->cities, 'provinces' => $this->provinces, 'user' => $this->user ])->render(); } // Fallback ke view asli jika diperlukan return view('lpj::penawaran.kirimEmail', [ 'penawaran' => $this->penawaran, 'permohonan' => $this->permohonan, 'villages' => $this->villages, 'districts' => $this->districts, 'cities' => $this->cities, 'provinces' => $this->provinces, 'user' => $this->user ])->render(); } /** * Send email using PHPMailer */ public function sendWithPHPMailer($recipients, $attachments = []) { try { $htmlContent = $this->buildHtml(); // Konfigurasi PHPMailer $mail = new PHPMailer(true); // Server settings - menggunakan konfigurasi yang sudah terbukti berhasil $mail->isSMTP(); $mail->Host = 'mail.ag.co.id'; $mail->SMTPAuth = true; $mail->Username = 'BAGI@ag.co.id'; $mail->Password = 'BAG@202!'; $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; $mail->Port = 465; // Bypass SSL Verification untuk menghindari certificate verify failed $mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); // Recipients if (is_array($recipients)) { foreach ($recipients as $recipient) { $mail->addAddress($recipient); } } else { $mail->addAddress($recipients); } // Content $mail->isHTML(true); $mail->Subject = 'Penawaran Tender Baru'; $mail->Body = $htmlContent; $mail->AltBody = strip_tags($htmlContent); // Add attachments if provided foreach ($attachments as $attachment) { if (is_array($attachment) && isset($attachment['path'])) { // Format array dengan nama custom $attachmentName = $attachment['name'] ?? basename($attachment['path']); if (file_exists($attachment['path'])) { $mail->addAttachment($attachment['path'], $attachmentName); } } elseif (is_string($attachment) && file_exists($attachment)) { // Format string sederhana $mail->addAttachment($attachment); } } $mail->send(); Log::info('Email penawaran tender berhasil dikirim menggunakan PHPMailer', [ 'recipients' => $recipients, 'attachments' => $attachments ]); return [ 'success' => true, 'message' => 'Email berhasil dikirim' ]; } catch (\Exception $e) { Log::error('Gagal mengirim email penawaran tender menggunakan PHPMailer', [ 'recipients' => $recipients, 'error' => $e->getMessage() ]); return [ 'success' => false, 'error' => $e->getMessage() ]; } } }