Files

61 lines
3.1 KiB
PHP
Executable File

<?php
if (isset($_POST['email'])) {
$user_email = $_POST['email'];
// HTML content for the user's confirmation email
$user_html = "
<div style='font-family: Arial, sans-serif; max-width: 600px; margin: auto; border: 1px solid #ddd; padding: 12px;'>
<div style='font-size: 20px; background: linear-gradient(45deg, #2E7D32, #4CAF50); color: #fff; text-align: center; padding: 20px;'><strong>Thank You for Subscribing!</strong></div>
<p style='font-size: 16px; text-align: center; color: #000;'>You have successfully subscribed to our newsletter</p>
<p style='background-color: #f4f4f4; color: #000; padding: 10px; border-radius: 5px; text-align: center;'><strong>Email:</strong> $user_email</p>
<p style='text-align: center; color: #000;'>Stay tuned for updates and exclusive offers!</p>
</div>";
// HTML content for the notification email to the website owner
$owner_html = "
<div style='font-family: Arial, sans-serif; max-width: 600px; margin: auto;border: 1px solid #ddd;'>
<h2 style='background: linear-gradient(45deg, #2E7D32, #4CAF50); color: #fff; text-align: center; padding: 20px; margin: 0;'>New Newsletter Subscriber</h2>
<div style='padding: 10px 15px;'>
<p style='font-size: 16px;'>You have a new subscriber:</p>
<p style='background-color: #f4f4f4; padding: 10px; border-radius: 5px; text-align: center;'><strong>Email:</strong> $user_email</p>
</div>
</div>";
// Include PHPMailer autoload file
require 'smtp/PHPMailerAutoload.php';
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
// SMTP settings
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->Port = 587; // TCP port to connect to
$mail->SMTPSecure = 'tls'; // Enable TLS encryption
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'your_email@gmail.com'; // SMTP username (your Gmail email)
$mail->Password = 'Your App Password'; // SMTP password (your app password from Gmail)
// Send confirmation email to the user
$mail->setFrom('your_email@gmail.com', 'LeafLine'); // Sender's email and name
$mail->addAddress($user_email); // User's email address
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Newsletter Subscription Confirmation'; // Email subject
$mail->Body = $user_html; // Email body
$mail->send();
// Send notification email to the website owner
$mail->clearAddresses(); // Clear previous recipients
$mail->addAddress('your_email@gmail.com', 'LeafLine'); // Recipient's email and name
$mail->Subject = 'New Newsletter Subscriber'; // Email subject
$mail->Body = $owner_html; // Email body
$mail->send();
$msg = "Thank you for subscribing!";
} catch (Exception $e) {
$msg = "Error occurred while sending email. Please try again later.";
}
echo $msg; // Output the result message
}
?>