diff --git a/EmailService.php b/EmailService.php index 57377f3..10356b9 100644 --- a/EmailService.php +++ b/EmailService.php @@ -122,12 +122,21 @@ class EmailService { */ private function sendViaSMTP($to, $subject, $text, $html = null) { try { + error_log('===== EMAIL SEND START ====='); + error_log('To: ' . $to); + error_log('Subject: ' . $subject); + error_log('Service: SMTP'); + $from = $this->config['from']; $host = $this->config['smtp_host']; $port = $this->config['smtp_port']; $username = $this->config['smtp_username']; $password = $this->config['smtp_password']; + error_log('SMTP Host: ' . $host . ':' . $port); + error_log('SMTP User: ' . $username); + error_log('From: ' . $from); + // Build email message with multipart if HTML provided $boundary = md5(time()); @@ -143,10 +152,11 @@ class EmailService { } // Create SMTP connection + error_log('Connecting to SMTP server...'); $socket = fsockopen($host, $port, $errno, $errstr, 10); if (!$socket) { - error_log('SMTP connection failed: ' . $errstr); + error_log('SMTP connection failed: ' . $errstr . ' (errno: ' . $errno . ')'); return [ 'success' => false, 'error' => 'SMTP connection failed', @@ -154,6 +164,8 @@ class EmailService { ]; } + error_log('SMTP connection established'); + // SMTP conversation $this->smtpCommand($socket, null, 220); // Wait for greeting $this->smtpCommand($socket, "EHLO " . $host, 250); @@ -185,12 +197,16 @@ class EmailService { $message .= ".\r\n"; + error_log('Sending email data...'); $this->smtpCommand($socket, $message, 250); + + error_log('Sending QUIT command...'); $this->smtpCommand($socket, "QUIT", 221); fclose($socket); - error_log('Email sent via SMTP to ' . $to); + error_log('✅ Email sent successfully via SMTP to ' . $to); + error_log('===== EMAIL SEND END (SUCCESS) ====='); return [ 'success' => true, @@ -198,7 +214,9 @@ class EmailService { ]; } catch (Exception $e) { - error_log('SMTP exception: ' . $e->getMessage()); + error_log('❌ SMTP exception: ' . $e->getMessage()); + error_log('Stack trace: ' . $e->getTraceAsString()); + error_log('===== EMAIL SEND END (FAILED) ====='); return [ 'success' => false,