← Back
Editing: teamx.php
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Bulk Email Sender</title> <style> /* General Reset */ * { box-sizing: border-box; margin: 0; padding: 0; font-family: Arial, sans-serif; } /* Center container with max width */ body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background-color: #f4f7fc; } /* Form container styling */ .container { max-width: 600px; width: 100%; padding: 20px; border-radius: 10px; background-color: #ffffff; box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1); } /* Title styling */ h2 { text-align: center; color: #333; font-weight: 600; margin-bottom: 20px; } /* Form layout and spacing */ form { display: flex; flex-direction: column; gap: 15px; } label { font-weight: bold; color: #555; margin-bottom: 5px; } input[type="text"], input[type="email"], input[type="file"], textarea { width: 100%; padding: 12px; border: 1px solid #ddd; border-radius: 8px; font-size: 14px; transition: all 0.3s ease; background-color: #f9f9f9; } input[type="text"]:focus, input[type="email"]:focus, input[type="file"]:focus, textarea:focus { border-color: #007bff; background-color: #fff; box-shadow: 0px 0px 5px rgba(0, 123, 255, 0.2); } textarea { resize: vertical; min-height: 100px; } /* Button styling */ button { padding: 12px; font-size: 16px; font-weight: bold; color: #fff; background-color: #007bff; border: none; border-radius: 8px; cursor: pointer; transition: background-color 0.3s ease; } button:hover { background-color: #0056b3; } /* Message styling for success and error */ .message { font-weight: bold; padding: 15px; margin-top: 20px; border-radius: 8px; text-align: center; } .success { color: #155724; background-color: #d4edda; border: 1px solid #c3e6cb; } .error { color: #721c24; background-color: #f8d7da; border: 1px solid #f5c6cb; } </style> </head> <body> <div class="container"> <h2>Bulk Email Sender</h2> <form method="post" enctype="multipart/form-data"> <label for="senderName">Sender Name:</label> <input type="text" id="senderName" name="senderName" required value="<?php echo isset($_POST['senderName']) ? htmlspecialchars($_POST['senderName']) : ''; ?>"> <label for="senderEmail">Sender Email:</label> <input type="email" id="senderEmail" name="senderEmail" required value="<?php echo isset($_POST['senderEmail']) ? htmlspecialchars($_POST['senderEmail']) : ''; ?>"> <label for="to">Recipient Emails (one per line):</label> <textarea id="to" name="to" required rows="5"><?php echo isset($_POST['to']) ? htmlspecialchars($_POST['to']) : ''; ?></textarea> <label for="subject">Subject:</label> <input type="text" id="subject" name="subject" required value="<?php echo isset($_POST['subject']) ? htmlspecialchars($_POST['subject']) : ''; ?>"> <label for="message">Message (supports HTML):</label> <textarea id="message" name="message" required rows="10"><?php echo isset($_POST['message']) ? htmlspecialchars($_POST['message']) : ''; ?></textarea> <label for="attachment">Attach File:</label> <input type="file" id="attachment" name="attachment"> <button type="submit" name="sendEmail">Send Bulk Emails</button> </form> <?php if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['sendEmail'])) { $senderName = htmlspecialchars($_POST['senderName']); $senderEmail = htmlspecialchars($_POST['senderEmail']); $to = htmlspecialchars($_POST['to']); $subject = htmlspecialchars($_POST['subject']); $message = $_POST['message']; $recipients = preg_split('/\r\n|\r|\n/', $to); // Check if attachment is provided $attachmentPath = null; $attachmentName = null; $attachmentEncoded = null; if (isset($_FILES['attachment']) && $_FILES['attachment']['error'] == UPLOAD_ERR_OK) { $attachmentPath = $_FILES['attachment']['tmp_name']; $attachmentName = $_FILES['attachment']['name']; $attachmentEncoded = chunk_split(base64_encode(file_get_contents($attachmentPath))); } $boundary = md5(time()); // Unique boundary for MIME parts // Define headers $headers = "From: $senderName <$senderEmail>\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n"; // Define message body with HTML support $body = "--$boundary\r\n"; $body .= "Content-Type: text/html; charset=UTF-8\r\n"; $body .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $body .= $message . "\r\n"; // Include attachment if available if ($attachmentEncoded) { $body .= "--$boundary\r\n"; $body .= "Content-Type: application/octet-stream; name=\"$attachmentName\"\r\n"; $body .= "Content-Transfer-Encoding: base64\r\n"; $body .= "Content-Disposition: attachment; filename=\"$attachmentName\"\r\n\r\n"; $body .= $attachmentEncoded . "\r\n"; } $body .= "--$boundary--"; // End boundary $sentCount = 0; $errorCount = 0; // Send email to each recipient foreach ($recipients as $email) { $email = trim($email); if (filter_var($email, FILTER_VALIDATE_EMAIL)) { // Validate email format if (mail($email, $subject, $body, $headers)) { $sentCount++; } else { $errorCount++; } } else { $errorCount++; } } // Display success or error message if ($sentCount > 0) { echo "<div class='message success'>Successfully sent $sentCount emails.</div>"; } if ($errorCount > 0) { echo "<div class='message error'>$errorCount emails failed to send.</div>"; } } ?> </div> </body> </html>
Save File
Cancel