XAMPP 自带的 Mercury 邮件服务器只能发不能收,本质是 SMTP 中继代理,无 POP3/IMAP 服务;PHP 的 mail() 默认不走 Mercury,需正确配置 php.ini(SMTP=localhost、smtp_port=25、sendmail_from=postmaster@localhost)、取消 Mercury 中“Do not permit SMTP relaying”勾选、启用 MercuryC SMTP Client 并配置 Smart host、设置本地用户密码,且 mail() 调用须加 -fpostmaster@localhost 参数。

直接说结论:XAMPP 自带的 Mercury 邮件服务器**只能发,不能收**;它本质是个“SMTP 中继代理”,不是完整邮件服务器(没有 POP3/IMAP 服务),所谓“收邮件”是误传。配置目标应明确为:让本地 PHP 脚本或外部程序(如 Joomla、表单)能通过 Mercury 向外发送邮件。
Mercury 启动后为什么 mail() 还是发不出?
因为 PHP 的 mail() 函数默认不走 Mercury,而是依赖系统 MTA(Windows 下需 sendmail.exe,但 XAMPP 7.4+ 已移除该目录)。即使 Mercury 在运行,mail() 仍会静默失败——没报错,也没邮件。
- 检查
php.ini中[mail function]段是否设为:SMTP = localhost和smtp_port = 25(不是 Gmail 的 587) -
sendmail_from必须是合法邮箱格式(如postmaster@localhost),否则部分 SMTP 服务器会拒收 - Apache 必须重启,改了
php.ini不重启等于白改 - Mercury 的 SMTP 服务端口必须是 25(不是 465 或 587),且绑定在
127.0.0.1上
Mercury Configuration / MercuryS SMTP Server 关键设置
这个界面决定 Mercury 是否允许你“代发”外部邮件(即中继)。默认勾选了 Do not permit SMTP relaying of non-local mail,这是最常被忽略的开关。
XAMPP 8.0.30 是一款免费、开源的跨平台 Web 服务器集成包,专为快速搭建本地 PHP 开发环境而设计。该版本核心组件包括:Apache 2.4.56、MySQL 8.0.33、PHP 8.0.30、phpMyAdmin 5.2.1 等。它支持 Windows、Linux 和 macOS 系统,可让开发者在个人电脑上轻松模拟服务器环境,无需复杂配置即可运行 WordPress、Thin
- 进
Connection control标签页 → **取消勾选**Do not permit SMTP relaying of non-local mail - 进
General标签页 →IP interface to use填127.0.0.1(别留空或填 0.0.0.0) -
Announce myself as可填任意名称(如localhost-smtp),但不能为空 - 确认
localhost已在Local domains列表里(路径:Configuration / Mercury core module / Local domains)
MercuryC SMTP Client 是对外发信的核心模块
Mercury 本身不连公网,它靠 MercuryC SMTP Client 模块把你的邮件转给真实 SMTP 服务商(如 Gmail、腾讯企业邮箱)。这一步配错,就彻底发不出去。
- 必须在
Protocol modules中勾选MercuryC SMTP relaying client,同时**取消勾选**MercuryE SMTP end-to-end delivery client(二者互斥) -
Smart host name填目标 SMTP 地址,例如:smtp.gmail.com(注意不是gmail-smtp.l.google.com) -
Connection port/type选587+TLS encryption via STARTTLS command(Gmail/Outlook/腾讯邮箱均用此组合) -
Login username和Password必须是真实邮箱账号 + 应用专用密码(Gmail 必须开两步验证后生成 16 位密码,**不是登录密码**)
PHP 调用 mail() 前必须设好本地用户认证
Mercury 默认只允许本地进程(如它自己的 “Send mail message” 功能)发信;PHP 是外部调用,需显式授权用户。
- 打开
Configuration / Manage local users - 选中
postmaster(或新建用户),点击Change→ 设置密码(如postmaster) - 在 PHP 脚本中,
mail()的第五个参数要加-fpostmaster@localhost(强制发件人身份) - 示例:
mail('test@example.com', 'subject', 'body', '', '-fpostmaster@localhost'); - 若跳过这步,常见错误是
553 We do not relay non-local mail, sorry
Mercury 最容易被卡住的地方,从来不是“怎么填”,而是“哪几个勾要取消”——尤其是 Do not permit SMTP relaying 和 MercuryE SMTP end-to-end delivery client 这两个默认开启的选项。它们像保险丝,一没拔掉,整个链路就断在第一步。

















