1<?php 2 3use PHPMailer\PHPMailer\PHPMailer; 4use PHPMailer\PHPMailer\Exception; 5 6require 'PHPMailer/src/Exception.php'; 7require 'PHPMailer/src/PHPMailer.php'; 8require 'PHPMailer/src/SMTP.php'; 9 10include "email-validation.inc"; 11 12// Check parameters 13if (empty($_POST['request']) || empty($_POST['email']) || 14 empty($_POST['maillist']) || empty($_POST['remoteip']) || 15 empty($_POST['referer'])) { 16 die("missing some parameters"); 17} 18 19// Check email address 20if (!is_emailable_address($_POST['email'])) { 21 die("Invalid email address"); 22} 23 24// Check request mode 25if (!in_array($_POST['request'], ["subscribe", "unsubscribe"])) { 26 die("Invalid request mode"); 27} 28 29// Check mailing list name 30if (!preg_match("!^[a-z0-9-]+$!", $_POST['maillist'])) { 31 die("Invalid mailing list name"); 32} 33 34// Generate needed subpart of email address 35$sub = str_replace("@", "=", $_POST['email']); 36 37date_default_timezone_set('Etc/UTC'); 38$mail = new PHPMailer; 39$mail->isSMTP(); 40$mail->SMTPDebug = 0; 41$mail->Host = 'mailout.php.net'; 42$mail->Port = 25; 43$mail->setFrom($_POST['email']); 44$mail->addAddress("{$_POST['maillist']}-{$_POST['request']}-$sub@lists.php.net"); 45$mail->Subject = "PHP Mailing List Website Subscription"; 46$mail->Body = "This was a request generated from the form at {$_POST['referer']} by {$_POST['remoteip']}"; 47$mail_sent = $mail->send(); 48 49if (!$mail_sent) { 50 die("Mailer Error: " . $mail->ErrorInfo); 51} 52