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

102 行
2.7 KiB
PHP

<?php
// SMTP测试脚本
require_once 'vendor/autoload.php';
echo "<h1>SMTP连接测试</h1>";
echo "<pre>";
// 测试不同的SMTP配置
$configs = [
[
'name' => '阿里云SSL 465',
'host' => 'smtp.qiye.aliyun.com',
'port' => 465,
'secure' => 'ssl'
],
[
'name' => '阿里云TLS 587',
'host' => 'smtp.qiye.aliyun.com',
'port' => 587,
'secure' => 'tls'
],
[
'name' => '阿里云无加密 25',
'host' => 'smtp.qiye.aliyun.com',
'port' => 25,
'secure' => ''
],
[
'name' => 'QQ邮箱SSL 465',
'host' => 'smtp.qq.com',
'port' => 465,
'secure' => 'ssl'
],
[
'name' => '163邮箱SSL 465',
'host' => 'smtp.163.com',
'port' => 465,
'secure' => 'ssl'
]
];
foreach ($configs as $config) {
echo "\n=== 测试: {$config['name']} ===\n";
echo "Host: {$config['host']}, Port: {$config['port']}, Secure: {$config['secure']}\n";
// 尝试TCP连接
$start = microtime(true);
$socket = @fsockopen($config['host'], $config['port'], $errno, $errstr, 10);
$time = round((microtime(true) - $start) * 1000, 2);
if ($socket) {
echo "✓ TCP连接成功 ({$time}ms)\n";
fclose($socket);
// 如果是SSL/TLS,测试SSL连接
if (!empty($config['secure'])) {
$start = microtime(true);
$context = stream_context_create([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
]);
$sslSocket = @stream_socket_client(
"{$config['secure']}://{$config['host']}:{$config['port']}",
$errno,
$errstr,
10,
STREAM_CLIENT_CONNECT,
$context
);
$time = round((microtime(true) - $start) * 1000, 2);
if ($sslSocket) {
echo "✓ SSL/TLS连接成功 ({$time}ms)\n";
fclose($sslSocket);
} else {
echo "✗ SSL/TLS连接失败: $errstr (errno: $errno)\n";
}
}
} else {
echo "✗ TCP连接失败: $errstr (errno: $errno) ({$time}ms)\n";
}
// 检查DNS解析
echo "\nDNS解析测试:\n";
$dns = @dns_get_record($config['host'], DNS_A);
if ($dns) {
echo "✓ DNS解析成功:\n";
foreach ($dns as $record) {
echo " - {$record['ip']}\n";
}
} else {
echo "✗ DNS解析失败\n";
}
echo "\n";
}
echo "</pre>";
?>