[[
'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 (first send)
*/
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 . '
|
|
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.
|
|
';
}
/**
* Build reminder email HTML (resend - 2nd/3rd dispatch)
* Same survey info as the first time but with a REMINDER banner and friendly nudge copy.
*/
function buildReminderEmail($proxy_url, $eloi, $incentive) {
$reward = '₹' . number_format($incentive, 0);
return '
Relevant Reflex
Survey Invitation
|
|
🔔 REMINDER: Your survey invitation is still waiting for you!
|
|
Dear Participant,
We noticed you haven\'t had a chance to take the survey we invited you to earlier. We would love to hear your opinion! The survey is still open and your participation would be greatly valued.
|
Estimated Duration
' . (int)$eloi . ' minutes
|
Reward
' . $reward . '
|
|
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.
|
|
';
}