文件
Parlz/test_smtp_new.php
2026-06-04 22:42:27 +08:00

77 行
2.1 KiB
PHP

<?php
// 测试新的SMTP服务器配置
require_once 'vendor/autoload.php';
echo "<h1>测试网易企业邮SMTP配置</h1>";
echo "<pre>";
$config = [
'host' => 'smtp.freeqiye.com',
'username' => 'noreply@parlz.com',
'password' => 'Zzr20130731'
];
// 测试不同端口
$ports = [
['port' => 465, 'secure' => 'ssl', 'name' => 'SSL 465'],
['port' => 587, 'secure' => 'tls', 'name' => 'TLS 587'],
['port' => 25, 'secure' => '', 'name' => '无加密 25']
];
foreach ($ports as $p) {
echo "\n=== 测试: {$p['name']} ===\n";
echo "Host: {$config['host']}, Port: {$p['port']}\n";
// TCP连接测试
$start = microtime(true);
$socket = @fsockopen($config['host'], $p['port'], $errno, $errstr, 10);
$time = round((microtime(true) - $start) * 1000, 2);
if ($socket) {
echo "✓ TCP连接成功 ({$time}ms)\n";
// 发送EHLO命令测试SMTP服务
fwrite($socket, "EHLO test\r\n");
$response = fgets($socket, 1024);
echo "EHLO响应: " . trim($response) . "\n";
fclose($socket);
} else {
echo "✗ TCP连接失败: $errstr (errno: $errno)\n";
}
}
// 完整的PHPMailer测试
echo "\n=== PHPMailer完整测试 ===\n";
$mail = new PHPMailer\PHPMailer\PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = $config['host'];
$mail->SMTPAuth = true;
$mail->Username = $config['username'];
$mail->Password = $config['password'];
$mail->SMTPSecure = ''; // 不使用加密
$mail->Port = 25;
$mail->Timeout = 30;
$mail->SMTPTimeout = 30;
$mail->SMTPDebug = 2;
$mail->Debugoutput = function($str, $level) {
echo "DEBUG [$level]: $str\n";
};
$mail->setFrom($config['username'], 'Parlz');
$mail->addAddress('test@example.com', 'Test User');
$mail->Subject = '测试邮件';
$mail->Body = '这是一封测试邮件';
echo "\n发送邮件...\n";
$mail->send();
echo "✓ 邮件发送成功!\n";
} catch (Exception $e) {
echo "✗ 邮件发送失败: " . $mail->ErrorInfo . "\n";
echo "异常信息: " . $e->getMessage() . "\n";
}
echo "</pre>";
?>