This commit is contained in:
Dr3amFury
2025-07-10 00:00:10 +02:00
commit 6af2403497
6 changed files with 433 additions and 0 deletions

65
README.txt Normal file
View File

@@ -0,0 +1,65 @@
AI Email Generator
==================
This is a simple AI-powered Email Generator tool that helps users turn rough email drafts into polished emails.
It uses OpenAI's GPT API (gpt-3.5-turbo) to generate emails in various tones and languages.
---
▶ FEATURES:
- Choose between 3 Tones: Formal, Casual, Persuasive
- Supports 25 Languages (English, Swedish, Spanish, French, German, etc.)
- Copy email to clipboard
- Save email as .txt file
- Toggle Dark Mode for better readability
---
▶ INSTALLATION:
1. Make sure your server has PHP 7.4+ and cURL enabled.
2. Create an OpenAI API Key from:
https://platform.openai.com/account/api-keys
3. Add your API key inside the `config.php` file like this:
```php
<?php
return [
'openai_api_key' => 'YOUR_OPENAI_API_KEY_HERE',
];
?>
```
---
▶ USAGE:
1. Open `index.php` in your browser.
2. Paste your rough email draft.
3. Select tone and language.
4. Click “Generate Email”.
5. Copy, save, or toggle dark mode as desired.
---
▶ FILES INCLUDED:
- index.php → Main form page
- process.php → Handles API requests and generates the email
- style.css → Styling for the tool (with dark mode)
- config.php → Configuration (API key)
- home.php → landing page
---
▶ NOTES:
- You need an active OpenAI API Key with sufficient quota.
- The tool works locally or on any PHP-compatible web server.
- If the buyer wants to integrate this tool into an existing website or system,
it is their responsibility to handle the integration. This tool is provided as a standalone solution.
---
▶ LICENSE:
This project is provided "as is" for personal or commercial use.
No liability is accepted for API costs or usage.
---

7
config.php Normal file
View File

@@ -0,0 +1,7 @@
<?php
// config.php
return [
'openai_api_key' => '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',
];
?>

26
home.php Normal file
View File

@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>AI Email Generator</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>AI Email Generator</h1>
<p>Effortlessly craft polished, professional emails in seconds.</p>
<a href="index.php"><button>Start Generating Emails</button></a>
<button id="darkModeBtn">Toggle Dark Mode</button>
</div>
<script>
const darkBtn = document.getElementById('darkModeBtn');
if (darkBtn) {
darkBtn.onclick = function () {
document.body.classList.toggle('dark-mode');
};
}
</script>
</body>
</html>

65
index.php Normal file
View File

@@ -0,0 +1,65 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>AI Email Generator</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>AI Email Generator</h1>
<form action="process.php" method="POST">
<label for="email_input">Your Rough Email:</label>
<textarea name="email_input" id="email_input" rows="8" required></textarea>
<label for="tone">Select Tone:</label>
<select name="tone" id="tone" required>
<option value="formal">Formal</option>
<option value="casual">Casual</option>
<option value="persuasive">Persuasive</option>
</select>
<label for="language">Select Language:</label>
<select name="language" id="language" required>
<option value="English">English</option>
<option value="Swedish">Swedish</option>
<option value="Spanish">Spanish</option>
<option value="French">French</option>
<option value="German">German</option>
<option value="Italian">Italian</option>
<option value="Portuguese">Portuguese</option>
<option value="Dutch">Dutch</option>
<option value="Norwegian">Norwegian</option>
<option value="Danish">Danish</option>
<option value="Finnish">Finnish</option>
<option value="Polish">Polish</option>
<option value="Czech">Czech</option>
<option value="Hungarian">Hungarian</option>
<option value="Greek">Greek</option>
<option value="Turkish">Turkish</option>
<option value="Russian">Russian</option>
<option value="Chinese">Chinese</option>
<option value="Japanese">Japanese</option>
<option value="Korean">Korean</option>
<option value="Arabic">Arabic</option>
<option value="Hebrew">Hebrew</option>
<option value="Hindi">Hindi</option>
<option value="Thai">Thai</option>
<option value="Vietnamese">Vietnamese</option>
</select>
<button type="submit">Generate Email</button>
<button id="darkModeBtn" type="button">Toggle Dark Mode</button>
</form>
</div>
<script>
const darkBtn = document.getElementById('darkModeBtn');
if (darkBtn) {
darkBtn.onclick = function () {
document.body.classList.toggle('dark-mode');
};
}
</script>
</body>
</html>

117
process.php Normal file
View File

@@ -0,0 +1,117 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>AI Email Generator - Result</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<?php
// Load API key from config
$config = include 'config.php';
$apikey = $config['openai_api_key'];
// Sanitize and validate user inputs
$emailInput = trim($_POST['email_input'] ?? '');
$tone = $_POST['tone'] ?? '';
$language = $_POST['language'] ?? 'English'; // Language selector
$allowedTones = [
'formal' => 'Write this email in a formal tone',
'casual' => 'Write this email in a casual tone',
'persuasive' => 'Write this email in a persuasive tone',
];
if (empty($emailInput) || !isset($allowedTones[$tone])) {
die('Invalid Input.');
}
// Improved Prompt with strict language response
$prompt = $allowedTones[$tone] . ". Transform this rough text into a polished, professional email in " . $language . ". ONLY reply in " . $language . ":\n\n" . $emailInput;
// Prepare API request
$apiurl = 'https://api.openai.com/v1/chat/completions';
$data = [
'model' => 'gpt-3.5-turbo',
'messages' => [
['role' => 'user', 'content' => $prompt],
],
'max_tokens' => 500,
'temperature' => 0.7,
];
$headers = [
'Content-Type: application/json',
'Authorization: Bearer ' . $apikey,
];
// Make API request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$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']);
echo "<h2>Your AI-Generated Email:</h2>";
echo "<div class='email-output'>";
echo "<pre>$aiEmail</pre>";
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 "</div>";
} else {
echo "Error: Failed to generate email. Try again later.";
}
?>
<div id="toast">Copied to clipboard ✔️</div>
</div>
<script>
const copyBtn = document.getElementById('copyBtn');
const saveBtn = document.getElementById('saveBtn');
const darkBtn = document.getElementById('darkModeBtn');
if (copyBtn) {
copyBtn.onclick = function () {
const text = document.querySelector('pre').innerText;
navigator.clipboard.writeText(text).then(() => {
const toast = document.getElementById('toast');
toast.classList.add('show');
setTimeout(() => toast.classList.remove('show'), 2000);
});
return false;
};
}
if (saveBtn) {
saveBtn.onclick = function () {
const text = document.querySelector('pre').innerText;
const blob = new Blob([text], { type: 'text/plain' });
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = 'email.txt';
link.click();
return false;
};
}
if (darkBtn) {
darkBtn.onclick = function () {
document.body.classList.toggle('dark-mode');
};
}
</script>
</body>
</html>

153
style.css Normal file
View File

@@ -0,0 +1,153 @@
/* Import Google Font */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap');
html {
box-sizing: border-box;
width: 100%;
overflow-x: hidden;
}
*, *::before, *::after {
box-sizing: inherit;
}
body {
background-color: #f5f7fa;
margin: 0;
font-family: 'Inter', Arial, sans-serif;
color: #333;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
padding: 40px 20px;
transition: background-color 0.3s ease, color 0.3s ease;
width: 100%;
}
body.dark-mode {
background-color: #121212;
color: #f5f5f5;
}
.container {
width: 100%;
max-width: 600px;
text-align: center;
padding: 20px;
}
form, .email-output {
padding: 25px;
background-color: #ffffff;
border-radius: 12px;
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
margin-top: 20px;
transition: background-color 0.3s ease, color 0.3s ease, transform 0.3s ease;
}
body.dark-mode form,
body.dark-mode .email-output {
background-color: #1e1e1e;
color: #f5f5f5;
}
label {
font-weight: bold;
display: block;
margin-bottom: 8px;
}
textarea, select {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
resize: vertical;
margin-bottom: 15px;
}
button {
background-color: #3498db;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease, transform 0.3s ease;
width: 100%;
}
button:hover {
background-color: #2980b9;
transform: translateY(-2px);
}
button + button {
margin-top: 10px;
}
#copyBtn {
background-color: #2ecc71;
}
#copyBtn:hover {
background-color: #27ae60;
}
.back-link {
display: inline-block;
margin-top: 15px;
color: #3498db;
text-decoration: none;
}
.back-link:hover {
text-decoration: underline;
}
#toast {
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
background-color: #2ecc71;
color: white;
padding: 12px 20px;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
transition: opacity 0.3s ease, visibility 0.3s ease;
opacity: 0;
visibility: hidden;
pointer-events: none;
z-index: 9999;
}
#toast.show {
opacity: 1;
visibility: visible;
}
@media (max-width: 600px) {
.container {
padding: 10px;
}
form, .email-output {
padding: 15px;
}
button {
padding: 10px;
}
}
.email-output button {
margin-top: 10px;
}
.email-output pre {
white-space: pre-wrap;
word-wrap: break-word;
}