<?php
session_start();
require_once 'vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$tonalityImages = [
'C Major' => 'https://horiamc.com/mail-img/tonalitati/C.png',
'C# Major' => 'https://horiamc.com/mail-img/tonalitati/Cd.png',
'D Major' => 'https://horiamc.com/mail-img/tonalitati/D.png',
'D# Major' => 'https://horiamc.com/mail-img/tonalitati/Dd.png',
'E Major' => 'https://horiamc.com/mail-img/tonalitati/E.png',
'F Major' => 'https://horiamc.com/mail-img/tonalitati/F.png',
'F# Major' => 'https://horiamc.com/mail-img/tonalitati/Fd.png',
'G Major' => 'https://horiamc.com/mail-img/tonalitati/G.png',
'G# Major' => 'https://horiamc.com/mail-img/tonalitati/Gd.png',
'A Major' => 'https://horiamc.com/mail-img/tonalitati/A.png',
'A# Major' => 'https://horiamc.com/mail-img/tonalitati/Ad.png',
'B Major' => 'https://horiamc.com/mail-img/tonalitati/B.png',
'C Minor' => 'https://horiamc.com/mail-img/tonalitati/Cm.png',
'C# Minor' => 'https://horiamc.com/mail-img/tonalitati/Cdm.png',
'D Minor' => 'https://horiamc.com/mail-img/tonalitati/Dm.png',
'D# Minor' => 'https://horiamc.com/mail-img/tonalitati/Ddm.png',
'E Minor' => 'https://horiamc.com/mail-img/tonalitati/Em.png',
'F Minor' => 'https://horiamc.com/mail-img/tonalitati/Fm.png',
'F# Minor' => 'https://horiamc.com/mail-img/tonalitati/Fdm.png',
'G Minor' => 'https://horiamc.com/mail-img/tonalitati/Gm.png',
'G# Minor' => 'https://horiamc.com/mail-img/tonalitati/Gdm.png',
'A Minor' => 'https://horiamc.com/mail-img/tonalitati/Am.png',
'A# Minor' => 'https://horiamc.com/mail-img/tonalitati/Adm.png',
'B Minor' => 'https://horiamc.com/mail-img/tonalitati/Bm.png',
];
$errorMessage = '';
$successMessage = '';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$recipientEmails = $_POST['recipient_email'];
$recipientEmails = explode(',', $recipientEmails);
foreach ($recipientEmails as $recipientEmail) {
// Trimiterea e-mailului așa cum ai făcut deja
}
$message = $_POST['message'];
$bpm = $_POST['bpm'];
$selectedTonality = $_POST['tonality'];
$audioFile = $_FILES['audio_file'];
if (!isset($audioFile) || !file_exists($audioFile['tmp_name'])) {
$errorMessage = "Fișierul încărcat nu există.";
}
$allowedExtensions = ['wav', 'mp3'];
$fileExtension = strtolower(pathinfo($audioFile['name'], PATHINFO_EXTENSION));
if (!in_array($fileExtension, $allowedExtensions)) {
$errorMessage = "Tipul de fișier nu este acceptat. Doar fișierele wav și mp3 sunt acceptate.";
}
if (!$errorMessage) {
$emailSubject = "{$_SESSION['username']} ti-a trimis o productie: {$audioFile['name']}";
$emailBody = "
<html>
<head>
<style>
body {
font-family: 'Segoe UI', sans-serif;
font-size: 16px;
line-height: 1.5;
color: #333;
background-color: #f4f4f4;
padding: 40px;
}
.container {
background-color: #fff;
border-radius: 5px;
padding: 30px;
max-width: 600px;
margin: auto;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
h1 {
font-size: 28px;
font-weight: bold;
margin-bottom: 20px;
}
p {
margin: auto;
text-align: center;
display: flex;
flex-direction: row;
align-content: center;
justify-content: flex-start;
align-items: center;
flex-wrap: wrap;
}
.footer {
font-size: 14px;
color: #888;
text-align: center;
margin-top: 30px;
}
img {
display: block;
max-width: 100%;
height: auto;
margin: 10px 0;
}
</style>
</head>
<body>
<div class='container'>
<h1>Noua ta producție</h1>
<p><strong>De la: </strong> {$_SESSION['username']}</p>
<p><strong>BPM: </strong> {$bpm}</p>
<p><strong>Tonalitate: </strong> {$selectedTonality}</p>
<p><strong>Mesaj: </strong> {$message}</p>
<img src='{$tonalityImages[$selectedTonality]}' alt='Notele din tonalitatea {$selectedTonality}' />
<p class='footer'>Acest e-mail a fost trimis automat. Vă rugăm să nu răspundeți la acest e-mail.</p>
</div>
</body>
</html>
";
foreach ($recipientEmails as $recipientEmail) {
$recipientEmail = trim($recipientEmail); // Eliminați spațiile albe de la începutul și sfârșitul fiecărei adrese de e-mail
if (!filter_var($recipientEmail, FILTER_VALIDATE_EMAIL)) {
// Skip if the email is not valid
continue;
}
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = 'mail.horiamc.com';
$mail->SMTPAuth = true;
$mail->Username = 'contact@horiamc.com';
$mail->Password = 'Pysquaifk!1@@';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('contact@horiamc.com', 'HoriaMC');
$mail->addReplyTo('reply-to@yourdomain.com', 'Reply To'); // Adăugați un header "Reply-To"
$mail->addAddress($recipientEmail);
$mail->Priority = 3; // Adaugă header de prioritate scăzută
$mail->isHTML(true); // Setează formatul e-mailului ca HTML
$mail->Subject = $emailSubject;
$mail->Body = $emailBody;
// Attach the audio file to the email
$mail->addAttachment($audioFile['tmp_name'], $audioFile['name']);
// Send the email
if ($mail->send()) {
$successMessage = "E-mailul a fost trimis cu succes!";
} else {
$errorMessage = "A apărut o eroare la trimiterea e-mailului.";
}
} catch (Exception $e) {
$errorMessage = "A apărut o eroare la trimiterea e-mailului: {$mail->ErrorInfo}";
} finally {
unset($mail);
}
}
}
}
$uploadError = $_FILES['audio_file']['error'];
if ($uploadError != UPLOAD_ERR_OK) {
switch ($uploadError) {
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
$errorMessage = "Fișierul încărcat este prea mare.";
break;
case UPLOAD_ERR_PARTIAL:
$errorMessage = "Fișierul a fost încărcat parțial.";
break;
case UPLOAD_ERR_NO_FILE:
$errorMessage = "Niciun fișier nu a fost încărcat.";
break;
case UPLOAD_ERR_NO_TMP_DIR:
$errorMessage = "Lipsește un director temporar.";
break;
case UPLOAD_ERR_CANT_WRITE:
$errorMessage = "Eroare la scrierea fișierului pe disc.";
break;
case UPLOAD_ERR_EXTENSION:
$errorMessage = "O extensie PHP a oprit încărcarea fișierului.";
break;
default:
$errorMessage = "A apărut o eroare la încărcarea fișierului.";
}
}
?>
<!DOCTYPE html>
<html lang="ro">
<head>
<script>
window.addEventListener('load', function() {
var loadingScreen = document.getElementById('loading-screen');
loadingScreen.style.opacity = 1;
setTimeout(function() {
loadingScreen.style.opacity = 0;
setTimeout(function() {
loadingScreen.style.display = 'none';
}, 1000);
}, 1000); // timpul în milisecunde pentru care se afișează ecranul de încărcare
});
</script>
<meta charset="UTF-8">
<title>Send Beats</title>
<style>
body {
background-color: #1e1f2b;
color: #fff;
font-family: 'Segoe UI', sans-serif;
font-size: 16px;
line-height: 1.5;
margin: 0;
padding: 0;
}
h1 {
font-size: 32px;
font-weight: 700;
margin-bottom: 24px;
}
label {
display: block;
font-size: 16px;
font-weight: 700;
margin-bottom: 8px;
margin-left: 8px;
}
input[type="file"], input[type="email"], input[type="number"], textarea, select {
background-color: #333;
border: none;
border-radius: 4px;
color: #fff;
font-family: 'Segoe UI', sans-serif;
font-size: 16px;
margin-bottom: 16px;
padding: 8px;
width: 100%;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}
input[type="file"] {
padding: 12px;
}
option {
color: #333;
}
button[type="submit"] {
background-color: #7f5af0;
border: none;
border-radius: 4px;
color: #fff;
cursor: pointer;
font-family: 'Segoe UI', sans-serif;
font-size: 16px;
font-weight: 700;
margin-top: 24px;
padding: 12px 24px;
transition: all 0.3s ease;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
margin-bottom: 10px;
}
button[type="submit"]:hover {
background-color: #5c3ab8;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}
p.success {
border-radius: 4px;
color: #fff;
font-weight: 700;
margin-bottom: 16px;
padding: 8px;
text-align: center;
}
p.error {
border-radius: 4px;
color: #fff;
font-weight: 700;
margin-bottom: 16px;
padding: 8px;
text-align: center;
}
#drop-container {
border: 2px dashed #ccc;
padding: 50px;
text-align: center;
cursor: pointer;
margin-bottom: 30px;
}
#drop-container:hover {
background-color: #413737;
}
#drop-container input {
display: none;
}
/* Media queries */
@media screen and (min-width: 768px) {
/* Center the form on larger screens */
form {
margin: 0 auto;
max-width: 480px;
}
}
nav {
background-color: #1e1f2b;
padding: 15px;
text-align: end;
}
nav a {
color: #fff;
text-decoration: none;
font-size: 18px;
margin-right: 15px;
}
nav a:hover {
color: #7f5af0;
}
#loading-screen {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.5);
z-index: 9999;
display: flex;
justify-content: center;
align-items: center;
backdrop-filter: blur(10px);
}
.spinner {
width: 50px;
height: 50px;
border: 5px solid rgba(0, 0, 0, 0.1);
border-top-color: #1e88e5;
border-radius: 50%;
animation: spinner 1s linear infinite;
}
@keyframes spinner {
to {
transform: rotate(360deg);
}
}
#loading-screen2 {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 9999;
display: flex;
justify-content: center;
align-items: center;
backdrop-filter: blur(10px);
}
#progressBarContainer {
width: 200px;
height: 10px;
background-color: rgba(255, 255, 255, 0.5);
border-radius: 5px;
overflow: hidden;
margin-top: 20px;
}
#progressBar {
height: 100%;
background-color: #4CAF50;
width: 0%;
transition: width 1s ease-in-out;
}
.email-input {
background-color: #333;
border: none;
border-radius: 4px;
color: #fff;
font-family: 'Segoe UI', sans-serif;
font-size: 16px;
margin-bottom: 16px;
padding: 8px;
width: 100%;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}
#recipient_email {
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
display: flex;
flex-wrap: wrap;
min-height: 36px;
}
.email-tag {
display: inline-flex;
align-items: center;
height: 28px;
background-color: #5c3ab899;
border-radius: 14px;
padding: 0 8px;
margin: 4px 4px 4px 0;
font-size: 14px;
}
.email-tag-content {
margin-right: 8px;
}
</style>
</head>
<body>
<div id="loading-screen">
<div class="spinner"></div>
</div>
<nav>
<a href="dashboard.php">Înapoi la Dashboard</a>
</nav>
<p class="success"><?php echo $successMessage; ?></p>
<p class="error"><?php echo $errorMessage; ?></p>
<form action="" method="post" enctype="multipart/form-data">
<div id="drop-container">
<label for="audio_file">Trage și plasează fișierul audio (wav, mp3):</label>
<input type="file" name="audio_file" id="audio_file" required>
<span id="file-name"></span>
</div>
<label for="recipient_email">E-mail destinatar(i):</label>
<div class="tag-container"></div>
<input type="text" id="recipient_email" class="email-input" placeholder="Introduceți adresele de e-mail separate prin virgulă">
<label for="bpm" class="form-label">BPM:</label>
<input type="number" name="bpm" id="bpm" class="form-control" required>
<label for="tonality" class="form-label">Tonalitate:</label>
<select name="tonality" id="tonality" class="form-select" required>
<option value="">Alege o tonalitate</option>
<optgroup label="Tonalități majore">
<option value="C Major">C Major</option>
<option value="C# Major">C# Major</option>
<option value="D Major">D Major</option>
<option value="D# Major">D# Major</option>
<option value="E Major">E Major</option>
<option value="F Major">F Major</option>
<option value="F# Major">F# Major</option>
<option value="G Major">G Major</option>
<option value="G# Major">G# Major</option>
<option value="A Major">A Major</option>
<option value="A# Major">A# Major</option>
<option value="B Major">B Major</option>
</optgroup>
<optgroup label="Tonalități minore">
<option value="C Minor">C Minor</option>
<option value="C# Minor">C# Minor</option>
<option value="D Minor">D Minor</option>
<option value="D# Minor">D# Minor</option>
<option value="E Minor">E Minor</option>
<option value="F Minor">F Minor</option>
<option value="F# Minor">F# Minor</option>
<option value="G Minor">G Minor</option>
<option value="G# Minor">G# Minor</option>
<option value="A Minor">A Minor</option>
<option value="A# Minor">A# Minor</option>
<option value="B Minor">B Minor</option>
</optgroup>
</select>
<label for="message">Mesaj:</label>
<textarea name="message" id="message" rows="5"></textarea>
<button type="submit" class="btn btn-primary mt-4">Trimite</button>
</form>
<script>
document.addEventListener('DOMContentLoaded', function () {
const fileInput = document.getElementById('audio_file');
const fileNameDisplay = document.getElementById('file-name');
fileInput.addEventListener('change', function (event) {
if (event.target.files.length > 0) {
const fileName = event.target.files[0].name;
fileNameDisplay.textContent = fileName;
} else {
fileNameDisplay.textContent = '';
}
});
const dropContainer = document.getElementById('drop-container');
dropContainer.addEventListener('dragover', function (event) {
event.preventDefault();
});
dropContainer.addEventListener('drop', function (event) {
event.preventDefault();
if (event.dataTransfer.files.length > 0) {
const fileName = event.dataTransfer.files[0].name;
fileNameDisplay.textContent = fileName;
fileInput.files = event.dataTransfer.files;
} else {
fileNameDisplay.textContent = '';
}
});
dropContainer.addEventListener('dragenter', () => {
dropContainer.style.border = '2px dashed #5c3ab8';
});
dropContainer.addEventListener('dragleave', () => {
dropContainer.style.border = '2px dashed #ccc';
});
})
document.querySelector("#recipient_email").addEventListener('keydown', function(e) {
if (e.key === 'Enter' || e.key === ',') {
e.preventDefault();
const inputValue = this.value.split(/[\s,]+/);
const lastValue = inputValue[inputValue.length - 1];
const emailPattern = /\S+@\S+\.\S+/;
if (emailPattern.test(lastValue)) {
const emailTag = document.createElement('span');
emailTag.className = 'email-tag';
const emailContent = document.createElement('span');
emailContent.className = 'email-tag-content';
emailContent.textContent = lastValue;
emailTag.appendChild(emailContent);
document.querySelector(".tag-container").appendChild(emailTag);
// Add a comma after the email address, but do not include the email address again
this.value += ',';
}
}
});
</script>
</body>
</html>