Email Generator
$prompt_text, 'max_tokens' => $word_limit, 'temperature' => 0.7 // Other parameters as needed ); $data_string = json_encode($data); // Convert data to JSON // Insert your API key here $api_key = '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'; // Replace 'YOUR_API_KEY' with your actual API key // Make the API request using cURL $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.openai.com/v1/engines/davinci/completions', CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $data_string, CURLOPT_HTTPHEADER => array( 'Authorization: Bearer ' . $api_key, 'Content-Type: application/json', 'Content-Length: ' . strlen($data_string) ) )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { $response_array = json_decode($response, true); if (isset($response_array['choices']) && is_array($response_array['choices']) && count($response_array['choices']) > 0) { echo "Generated Email:
"; echo '';
echo '
';
} else {
echo "No valid 'choices' key found in the response.";
var_dump($response_array);
}
}
}
?>
Generated Email Response:
'; echo '' . htmlspecialchars($response_array['choices'][0]['text']) . '
'; echo '