[[ '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 '

Relevant Reflex

Survey Invitation

Dear Participant,

You have been selected to participate in an online survey. Your opinions are valuable and will help shape important decisions. We would greatly appreciate your time and input.

Estimated Duration

' . (int)$eloi . ' minutes

Reward

' . $reward . '

Take Survey Now →

If the button above doesn\'t work, copy and paste this URL into your browser:

' . htmlspecialchars($proxy_url) . '

Please complete the survey at your earliest convenience. Your responses are completely confidential and will be used for research purposes only.

© ' . date('Y') . ' Relevant Reflex India. All rights reserved.

You are receiving this email because you are a registered member of the Relevant Reflex panel.

'; }