[[ 'to' => [['email' => $to_email]], 'subject' => $subject ]], 'from' => [ 'email' => SENDER_EMAIL, 'name' => SENDER_NAME ], 'content' => [[ 'type' => 'text/html', 'value' => $html_content ]] ]; $ch = curl_init('https://api.sendgrid.com/v3/mail/send'); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_POSTFIELDS => json_encode($data), CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . SENDGRID_API_KEY, 'Content-Type: application/json' ], CURLOPT_TIMEOUT => 10, CURLOPT_SSL_VERIFYPEER => true ]); $response = curl_exec($ch); $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $curl_error = curl_error($ch); curl_close($ch); if ($curl_error) { return ['success' => false, 'message' => 'cURL error: ' . $curl_error, 'status_code' => 0]; } // SendGrid returns 202 Accepted if ($status_code === 202) { return ['success' => true, 'message' => 'Email sent', 'status_code' => 202]; } $err = json_decode($response, true); $msg = $err['errors'][0]['message'] ?? ('HTTP ' . $status_code); return ['success' => false, 'message' => $msg, 'status_code' => $status_code]; } /** * Calculate default incentive (in RUPEES) * Reads pricing_base_incentive and pricing_loi_increment_incentive from company_settings * (same source as estimator.php and view-project.php). Falls back to safe defaults if * settings cannot be loaded. */ function calculateDefaultIncentive($eloi) { static $base = null, $incr = null; if ($base === null) { $base = 10; $incr = 1; // safe defaults try { $pdo = getClientDBConnection(); $stmt = $pdo->query("SELECT setting_key, setting_value FROM company_settings WHERE setting_key IN ('pricing_base_incentive', 'pricing_loi_increment_incentive')"); while ($r = $stmt->fetch(PDO::FETCH_ASSOC)) { if ($r['setting_key'] === 'pricing_base_incentive') $base = (float)$r['setting_value']; elseif ($r['setting_key'] === 'pricing_loi_increment_incentive') $incr = (float)$r['setting_value']; } } catch (Exception $e) { error_log('calculateDefaultIncentive pricing load failed: ' . $e->getMessage()); } } $extra = max(0, floor($eloi) - 5); return $base + ($extra * $incr); } /** * Build invitation email HTML (first send) */ function buildInvitationEmail($proxy_url, $eloi, $incentive) { $reward = '₹' . number_format($incentive, 0); return '