saved emails, gmail, hotmail start, home, landing etc
This commit is contained in:
53
process.php
53
process.php
@@ -1,21 +1,24 @@
|
||||
<?php
|
||||
require_once($_SERVER['DOCUMENT_ROOT'] . '/config.php');
|
||||
include($_SERVER['DOCUMENT_ROOT'] . '/inc/php/header.php');
|
||||
require_once($_SERVER['DOCUMENT_ROOT'] . '/db.php');
|
||||
require_once($_SERVER['DOCUMENT_ROOT'] . '/inc/php/auth.php');
|
||||
$conn = getConnection();
|
||||
require_once($_SERVER['DOCUMENT_ROOT'] . '/config.php');
|
||||
include($_SERVER['DOCUMENT_ROOT'] . '/inc/php/header.php');
|
||||
require_once($_SERVER['DOCUMENT_ROOT'] . '/db.php');
|
||||
require_once($_SERVER['DOCUMENT_ROOT'] . '/inc/php/auth.php');
|
||||
$conn = getConnection();
|
||||
|
||||
$user_id = $_SESSION['user_id'] ?? null;
|
||||
?>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<?php
|
||||
// Load API key from config
|
||||
// Load API key
|
||||
$apikey = getApi();
|
||||
|
||||
// Sanitize and validate user inputs
|
||||
// Sanitize inputs
|
||||
$emailInput = trim($_POST['email_input'] ?? '');
|
||||
$tone = htmlspecialchars($_POST['tone']) ?? '';
|
||||
$language = htmlspecialchars($_POST['language']) ?? 'English'; // Language selector
|
||||
$tone = isset($_POST['tone']) ? htmlspecialchars($_POST['tone']) : '';
|
||||
$language = isset($_POST['language']) ? htmlspecialchars($_POST['language']) : 'English';
|
||||
|
||||
|
||||
$allowedTones = [
|
||||
'formal' => 'Write this email in a formal tone',
|
||||
@@ -27,12 +30,11 @@
|
||||
die('Invalid Input.');
|
||||
}
|
||||
|
||||
// Improved Prompt with strict language response
|
||||
// Build prompt
|
||||
$prompt = $allowedTones[$tone] . ". Transform this rough text into a polished, professional email in " . $language . ". ONLY reply in " . $language . ":\n\n" . $emailInput;
|
||||
|
||||
// Prepare API request
|
||||
// API call
|
||||
$apiurl = 'https://api.openai.com/v1/chat/completions';
|
||||
|
||||
$data = [
|
||||
'model' => 'gpt-3.5-turbo',
|
||||
'messages' => [
|
||||
@@ -47,7 +49,6 @@
|
||||
'Authorization: Bearer ' . $apikey,
|
||||
];
|
||||
|
||||
// Make API request
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $apiurl);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
@@ -58,18 +59,31 @@
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
// Handle response
|
||||
$result = json_decode($response, true);
|
||||
|
||||
if (isset($result['choices'][0]['message']['content'])) {
|
||||
$aiEmail = htmlspecialchars($result['choices'][0]['message']['content']);
|
||||
$aiEmail = trim($result['choices'][0]['message']['content']);
|
||||
$safeEmail = htmlspecialchars($aiEmail);
|
||||
|
||||
echo "<h2>Your AI-Generated Email:</h2>";
|
||||
echo "<div class='email-output'>";
|
||||
echo "<pre>$aiEmail</pre>";
|
||||
echo "<pre>$safeEmail</pre>";
|
||||
|
||||
// Copy / Save / Navigation
|
||||
echo "<button id='copyBtn'>Copy Email</button>";
|
||||
echo "<button id='saveBtn'>Save Email as .txt</button>";
|
||||
echo "<button id='darkModeBtn'>Toggle Dark Mode</button>";
|
||||
echo "<a href='index.php' class='back-link'>← Generate Another Email</a>";
|
||||
echo "<a href='/home.php'><button>🏠 Back to Home</button></a>";
|
||||
echo "<a href='/inc/php/generate.php' class='back-link'>← Generate Another Email</a>";
|
||||
|
||||
// NEW: Save to DB form
|
||||
if ($user_id) {
|
||||
echo "<form method='POST' action='/inc/php/save_email.php' style='margin-top:15px;'>";
|
||||
echo "<input type='hidden' name='email_body' value=\"" . htmlspecialchars($aiEmail, ENT_QUOTES) . "\">";
|
||||
echo "<input type='text' name='subject' placeholder='Subject (optional)'>";
|
||||
echo "<button type='submit'>💾 Save to My Account</button>";
|
||||
echo "</form>";
|
||||
}
|
||||
|
||||
echo "</div>";
|
||||
} else {
|
||||
echo "Error: Failed to generate email. Try again later.";
|
||||
@@ -81,7 +95,6 @@
|
||||
<script>
|
||||
const copyBtn = document.getElementById('copyBtn');
|
||||
const saveBtn = document.getElementById('saveBtn');
|
||||
const darkBtn = document.getElementById('darkModeBtn');
|
||||
|
||||
if (copyBtn) {
|
||||
copyBtn.onclick = function () {
|
||||
@@ -107,4 +120,4 @@
|
||||
};
|
||||
}
|
||||
</script>
|
||||
<?php include($_SERVER['DOCUMENT_ROOT'] . '/inc/php/footer.php');
|
||||
<?php include($_SERVER['DOCUMENT_ROOT'] . '/inc/php/footer.php'); ?>
|
||||
|
||||
Reference in New Issue
Block a user