This page is a translated version of the page Manual:$wgSMTP and the translation is 64% complete.
电子邮件设置: $wgSMTP


要为通知、身份验证或 Special:Emailuser 发送邮件,你需要使用第三方电子邮件服务提供商并允许 MediaWiki 使用 SMTP 发送邮件。 配置信息以数组形式存储在 $wgSMTP 中。 将其设置为 false (默认值) 可以使用内置的 PHP mail() 功能,但请注意,如果你这样做,你的邮件很可能会进入用户的垃圾邮件文件夹。

还要配置 $wgEmergencyContact 并确保 $wgPasswordSender 与发送电子邮件地址匹配。


$wgSMTP = [
    'host'      => '', // SMTP服务器的地址,可以是IP地址的形式。 如果SMTP服务器使用SSL/TLS,请加上"ssl://"或"tls://"前缀。
    'IDHost'    => '',      // 通常这将是您网站的域名(例如
    'localhost' => '',      // 与上述 IDHost 相同;某些邮件服务器需要
    'port'      => 587,                // 连接到 SMTP 服务器提供服务的端口。
    'auth'      => true,               // 是否使用 SMTP 身份验证(true 或 false)。
    'username'  => 'my_user_name',     // 使用 SMTP 身份验证时所需的用户名。
    'password'  => 'my_password'       // 使用 SMTP 身份验证时所需的密码。

IDHost 是一个 MediaWiki 特有的设置,用于构建 Message-ID 电子邮件标头(有关正确格式化的 Message-ID 的更多信息,请参阅 RFC 2822,第 3.6.4 节)。 如果未提供,将默认为 $wgServer 。 对于其余设置,请参阅 Mail::factory() 以获得更完整的描述。 (向下滚动到 smtp 参数。)



Error sending mail: Unknown error in PHP's mail() function MediaWiki

Be sure that $wgEmergencyContact and $wgPasswordSender are set correctly, and match your email address. Some hosts will reject to send an email with a sender that doesn't match the account that sends the email.

If your server has SELinux enabled, be sure to configure it correctly to enable sending mails from the webserver.

Error sending mail: authentication failure SMTP: STARTTLS

PEAR 的 mail 程序在邮件服务器支持TLS[1]的时候会尽量使用TLS协议连接邮件服务器,即使你没有指定邮件服务器使用 ssl:// 协议。 但是如果服务器证书无效(证书[2]不被信任,证书过期,证书常用名[3]与服务器名或者IP不相符之类),程序会不工作,相应地你会得到以下错误提示:

authentication failure [SMTP: STARTTLS failed (code: 220, response: begin TLS negotiation)]



If the incorrect port is used, email will timeout without returning an error, and the website will appear unresponsive to the user. Consult your email provider's manual or try the other common SMTP ports: 25, 465, and 587.

Timeout issues with AWS SES

By default, Amazon EC2 throttles traffic on SMTP port 25 for all instances. If you continue to receive timeout errors using SMTP port 25, you can request that the throttle be removed or you can change the port that is used for sending (for example, 587). For more information, see How do I troubleshoot SMTP connectivity or timeout issues with Amazon SES?

require_once(): Failed opening required Net/Socket.php

Check your LocalSettings.php for any lines that call set_include_path. These should not be needed but can mess up SMTP support. Remove them from LocalSettings.php if present.

Mailserver does not accept sender (From)

If you are not able to send any email because your mailserver says something like "you are not authorized to use this sender" (or something like that), first check if your "SMTP username" is consistent with your email sender (see $wgPasswordSender ) then, if you have an old wiki, see $wgUserEmailUseReplyTo .

If you don't solve it, contact your mailserver.