?????????? ????????? - ??????????????? - /home/agenciai/public_html/cd38d8/campaign.php.tar
???????
home/agenciai/public_html/php_mailer/campaign.php 0000644 00000013646 15124777770 0016201 0 ustar 00 <?php require_once 'config.php'; requireLogin(); $emailLists = getEmailLists(); // Handle campaign submission if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['subject'])) { $listId = $_POST['list_id']; $subject = $_POST['subject']; $message = $_POST['message']; $subscribers = getSubscribersFromList($listId); if (empty($subscribers)) { header('Location: campaign.php?error=No+subscribers+in+selected+list'); exit; } // Get SMTP profile $smtpProfile = getSelectedSMTPProfile(); if (!$smtpProfile) { header('Location: campaign.php?error=No+SMTP+profile+configured'); exit; } require_once 'load_phpmailer.php'; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\Exception; $successCount = 0; $failCount = 0; $errors = []; foreach ($subscribers as $subscriber) { $mail = new PHPMailer(true); try { // Configure SMTP $mail->SMTPDebug = SMTP::DEBUG_OFF; $mail->isSMTP(); $mail->Host = $smtpProfile['host']; $mail->SMTPAuth = true; $mail->Username = $smtpProfile['username']; $mail->Password = $smtpProfile['password']; $mail->SMTPSecure = $smtpProfile['encryption']; $mail->Port = $smtpProfile['port']; // Set recipients $mail->setFrom($smtpProfile['from_email'], $smtpProfile['from_name']); $mail->addAddress($subscriber['email'], $subscriber['name']); // Content $mail->isHTML(true); $mail->Subject = $subject; // Personalize message $personalizedMessage = str_replace( ['{{name}}', '{{username}}', '{{email}}'], [$subscriber['name'], extractUsernameFromEmail($subscriber['email']), $subscriber['email']], $message ); $mail->Body = $personalizedMessage; $mail->AltBody = strip_tags($personalizedMessage); // Send $mail->send(); $successCount++; // Log success logSentEmail($subscriber['email'], $subject, 'success'); // Add delay to avoid overwhelming SMTP server (1 second) sleep(1); } catch (Exception $e) { $failCount++; $errorMsg = $mail->ErrorInfo; $errors[] = "Failed to send to {$subscriber['email']}: {$errorMsg}"; logSentEmail($subscriber['email'], $subject, 'failed', $errorMsg); } } // Show results $resultMessage = "Campaign sent! Success: {$successCount}, Failed: {$failCount}"; if (!empty($errors)) { $resultMessage .= "<br><br>Errors:<br>" . implode("<br>", array_slice($errors, 0, 5)); if (count($errors) > 5) { $resultMessage .= "<br>... and " . (count($errors) - 5) . " more errors."; } } header('Location: campaign.php?success=' . urlencode($resultMessage)); exit; } // Personalize message $personalizedMessage = str_replace( ['{{name}}', '{{username}}', '{{email}}'], [$subscriber['name'], extractUsernameFromEmail($subscriber['email']), $subscriber['email']], $message ); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Send Campaign</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body class="bg-light"> <div class="container py-5"> <div class="row justify-content-center"> <div class="col-md-10"> <div class="d-flex justify-content-between align-items-center mb-4"> <h2>Send Email Campaign</h2> <a href="index.php" class="btn btn-secondary">Back to Dashboard</a> </div> <div class="card"> <div class="card-body"> <form method="POST"> <div class="mb-3"> <label class="form-label">Select Email List</label> <select class="form-select" name="list_id" required> <option value="">-- Select a List --</option> <?php foreach ($emailLists as $listId => $list): ?> <option value="<?= $listId ?>"> <?= htmlspecialchars($list['name']) ?> (<?= count($list['subscribers'] ?? []) ?> subscribers) </option> <?php endforeach; ?> </select> </div> <div class="mb-3"> <label class="form-label">Subject *</label> <input type="text" class="form-control" name="subject" required> </div> <div class="mb-3"> <label class="form-label">Message (HTML) *</label> <textarea class="form-control" name="message" rows="10" required></textarea> <div class="form-text"> Use <code>{{name}}</code>, <code>{{username}}</code>, and <code>{{email}}</code> to personalize the message. Example: "Hello {{name}}, your username is {{username}} and email is {{email}}" </div> </div> </div> <button type="submit" class="btn btn-primary">Send Campaign</button> </form> </div> </div> </div> </div> </div> </body> </html>