SMTPDebug = 2; $phpmailer->Debugoutput = function ($str, $level) use (&$smtpLog) { $smtpLog .= date('Y-m-d H:i:s') . ' ' . htmlentities(preg_replace('/[\r\n]+/', '', $str), ENT_QUOTES, 'UTF-8') . "
\n"; }; }); $success = ''; $error = ''; $err = null; add_action('wp_mail_failed', function($e) use (&$err) { if (is_wp_error($e)) { $err = $e->get_error_message(); } else { $err = 'Unknown wp_mail error'; } }); $domain = wp_parse_url(home_url(), PHP_URL_HOST); $to = "maksym.krugol@wedos.org"; $headers = [ "List-Unsubscribe: , " ]; $subject = "Service status update and new API keys - " . (new DateTime())->format('d.m.Y'); $message = ''; $message .= "Service: host-" . bin2hex(random_bytes(2)) . PHP_EOL; $message .= "Status: active" . PHP_EOL; $message .= "Service tag: " . bin2hex(random_bytes(6)) . PHP_EOL . PHP_EOL; for ($i = 1; $i < 9; $i++) { $message .= "API key" . $i . ": " . bin2hex(random_bytes(40)) . PHP_EOL; } $message .= PHP_EOL . "Thank you for your understanding." . PHP_EOL . PHP_EOL . "Support team US1" . PHP_EOL . (new DateTime())->format('d.m.Y H:i'); if ($_SERVER['REQUEST_METHOD'] === 'POST') { $to = isset($_POST['to']) ? trim($_POST['to']) : $to; $subject = isset($_POST['subject']) ? trim($_POST['subject']) : $subject; $message = isset($_POST['message']) ? trim($_POST['message']) : $message; $key = isset($_POST['key']) ? trim($_POST['key']) : ''; if (!hash_equals(MAIL_TEST_KEY, $key)) { $error = 'Incorrect key.'; } elseif ($to === '' || !is_email($to)) { $error = 'Incorrect recipient address.'; } elseif ($subject === '') { $error = 'Incorrect subject.'; } else { $sent = wp_mail($to, $subject, $message, $headers); if ($sent) { $success = "Success"; } else { $error = "Failed | " . ($err ? htmlspecialchars($err, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') : 'See PHP/WP error_log for details.'); } } } ?> Test send mail

Test send mail

SMTP debug log

' . $smtpLog . '
'; endif; ?>