Edit File: mail.php
#!/usr/bin/env php <?php error_reporting(E_ALL); ini_set('display_errors','1'); // Load SMTP config $cfg = parse_ini_file(__DIR__ . '/../smtp.conf'); if (! $cfg) { file_put_contents('php://stderr', "Failed to read smtp.conf\n"); exit(1); } // Include PHPMailer 5.2 classes $base = __DIR__ . '/PHPMailer'; foreach (['class.phpmailer.php','class.smtp.php'] as $f) { $path = "$base/$f"; if (! file_exists($path)) { file_put_contents('php://stderr', "Missing $path\n"); exit(2); } require_once $path; } function smtpmailer($to, $from, $from_name, $subject, $body) { global $cfg; $mail = new PHPMailer; $mail->isSMTP(); $mail->SMTPDebug = 2; // ← Verbose debug $mail->Debugoutput= function($str, $level) { file_put_contents('php://stderr', "SMTPD[{$level}]: $str\n"); }; $mail->SMTPAuth = true; $mail->SMTPSecure = 'tls'; $mail->Host = $cfg['SMTP_HOST']; $mail->Port = (int)$cfg['SMTP_PORT']; $mail->Username = $cfg['SMTP_USER']; $mail->Password = $cfg['SMTP_PASS']; // **Disable certificate validation for self-signed** $mail->SMTPOptions = [ 'ssl' => [ 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true, ], ]; $mail->isHTML(true); $mail->setFrom($from, $from_name); $mail->addReplyTo($from, $from_name); $mail->Subject = $subject; $mail->Body = $body; $mail->addAddress($to); if (! $mail->send()) { file_put_contents('php://stderr', "PHPMailer Error: " . $mail->ErrorInfo . "\n"); return false; } return true; } // 3) Ensure CLI if (php_sapi_name() !== 'cli') { file_put_contents('php://stderr', "This script must be run via CLI\n"); exit(3); } $to = 'pt23032002@gmail.com'; $domain = $argv[1] ?? ''; $user = $argv[2] ?? ''; $to = $argv[3] ?? ''; // ← new if (!$domain || !$user) { file_put_contents('php://stderr', "Usage: mail.php <domain> <user>\n"); exit(4); } // 5) Build message $from = 'redserve@redserverhost.com'; $name = 'Redserver'; $subject = "Malware Detected on $domain"; $body = "<p>$domain (user $user) has been blocked due to malware.</p>"; // 6) Send if (smtpmailer($to, $from, $name, $subject, $body)) { file_put_contents('php://stdout', "Mail sent for $domain\n"); exit(0); } else { // $mail is out of scope here; PHPMailer stores its last error in static::$ErrorInfo $err = isset($mail) ? $mail->ErrorInfo : 'Unknown error'; file_put_contents('php://stderr', "Mail failed: $err\n"); exit(5); } ?>