[[ '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 => 30, 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 * Base: ₹10 for up to 5 min LOI * Extra: ₹1 per minute beyond 5 min */ function calculateDefaultIncentive($eloi) { $base = 10; $extra = max(0, $eloi - 5); return $base + $extra; } /** * Build invitation email HTML */ function buildInvitationEmail($proxy_url, $eloi, $incentive) { $reward = '₹' . number_format($incentive, 0); return '