php 如何在 Wordpress 中启用邮件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24841038/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:30:07  来源:igfitidea点击:

How can I enable mail in Wordpress?

phpwordpress

提问by

I'm using Apache 2.2.25 and PHP 5.3.28 in my Windows 8 desktop. Once when I was recovering my wordpress password, I got this error:

我在 Windows 8 桌面上使用 Apache 2.2.25 和 PHP 5.3.28。有一次,当我恢复我的 wordpress 密码时,我收到了这个错误:

The e-mail could not be sent. Possible reason: your host may have disabled the mail() function.

无法发送电子邮件。可能的原因:您的主机可能禁用了 mail() 功能。

I googled it that how can I enable mail() function, found that I need to configure a mail server with my server. I downloaded hMailServer, but it didn't work... Please help me how can I enable mail() function? Which mail server will I have to download?

我在 google 上搜索了如何启用 mail() 功能,发现我需要用我的服务器配置一个邮件服务器。我下载了hMailServer,但是没有用... 请帮我如何启用mail() 功能?我必须下载哪个邮件服务器?

回答by Simon East

As I posted here:

正如我在这里发布的

This is a super annoying error message as it could be manythings, and it doesn't reveal the actual error (which is often silenced in other parts of the code).

这是一个超级烦人的错误消息,因为它可能有很多东西,而且它没有揭示实际的错误(通常在代码的其他部分被忽略)。

This error appears when the wp_mail()function returns false, which in turn could happen if phpmailer->Send()returns false or raises an exception.

wp_mail()函数返回 false时会出现此错误,如果phpmailer->Send()返回 false 或引发异常,则可能会发生这种情况。



How to display warnings from PHP's mail()function

如何显示来自 PHPmail()函数的警告

These are normally silenced by default, and unfortunately WordPress never captures them. To show them, simply remove the @signs from @mail(...in wp-includes/class-phpmailer.phpin the mailPassthru()function:

默认情况下,这些通常是静音的,不幸的是 WordPress 从未捕获它们。向他们展示,只需删除@从标志@mail(...wp-includes/class-phpmailer.phpmailPassthru()功能:

if (ini_get('safe_mode') || !($this->UseSendmailOptions)) {
    $rt = @mail($to, $this->encodeHeader($this->secureHeader($subject)), $body, $header);
} else {
    $rt = @mail($to, $this->encodeHeader($this->secureHeader($subject)), $body, $header, $params);
}



How to hunt down other possible causes:

如何寻找其他可能的原因:

  1. Add a single line to the bottom of wp_mail()in /wp-includes/pluggable.php:

    // Send!
    try {
        return $phpmailer->Send();
    } catch ( phpmailerException $e ) {
        //------------- This next line is the one to add -------------------
        if (WP_DEBUG) echo '<pre>' . esc_html(print_r($e, TRUE)) . '</pre>';
        return false;
    }
    
  2. It will dump the full details of where the exception was raised. Unfortunately it sometimes includes this unhelpful exception message: "Could not instantiate mail function". Yeah thanks WordPress, that's real helpful.

  3. By looking at the exception you can find the line number of the error, and can hopefully trace it back through the code to find the real cause.

  1. wp_mail()在 in的底部添加一行/wp-includes/pluggable.php

    // Send!
    try {
        return $phpmailer->Send();
    } catch ( phpmailerException $e ) {
        //------------- This next line is the one to add -------------------
        if (WP_DEBUG) echo '<pre>' . esc_html(print_r($e, TRUE)) . '</pre>';
        return false;
    }
    
  2. 它将转储引发异常的完整细节。不幸的是,它有时会包含此无用的异常消息:“无法实例化邮件功能”。是的,谢谢 WordPress,这真的很有帮助。

  3. 通过查看异常,您可以找到错误的行号,并有望通过代码进行追溯以找到真正的原因。

Good luck. Hopefully WordPress improves email error handling at some point in the future.

祝你好运。希望 WordPress 在未来的某个时候改进电子邮件错误处理。

回答by Kenny Wyland

I encountered this same problem and nothing I could find in any of the suggestions for WordPress solved it for me.

我遇到了同样的问题,但我在 WordPress 的任何建议中都找不到任何解决方案。

Then I started investigating if it was the PHP installation itself that had disabled the mail function, but none of that worked either. Everything looked like it was configured properly.

然后我开始调查是否是 PHP 安装本身禁用了邮件功能,但这些都不起作用。一切看起来都配置正确。

All of these problems started for me once I upgraded my server to CentOS 7 which uses SELinux (Security Enhanced Linux) and what I've learned in the last couple of weeks with SELinux is that if something isn't working, but everything looks like it should be working... that means SELinux is silently and secretly blocking you in the background.

一旦我将服务器升级到使用 SELinux(安全增强型 Linux)的 CentOS 7,所有这些问题就开始出现在我身上,而我在过去几周使用 SELinux 学到的是,如果某些东西不起作用,但一切看起来像它应该可以工作……这意味着 SELinux 在后台悄悄地、秘密地阻止你。

And viola.

还有中提琴。

If you are running and OS that uses SELinux, just execute the following command as root:

如果您正在运行且使用 SELinux 的操作系统,只需以 root 身份执行以下命令:

setsebool -P httpd_can_sendmail=1

setsebool -P httpd_can_sendmail=1

There is a security setting that inherently prevents the webserver from sending email. When you flip that switch and tell SELinux it's ok for the webserver to send email, everything suddenly works.

有一个安全设置可以阻止网络服务器发送电子邮件。当你拨动那个开关并告诉 SELinux 网络服务器可以发送电子邮件时,一切都突然正常了。

回答by Amrit Bhandari

it called -Manage Registered Email-Ids For Sending Mails via Scripts(Wordpress)

它称为 -Manage Registered Email-Ids For Sending Mails via Scripts(Wordpress)

  1. Login your Cpanel.
  2. Go to Email Section > then Click Registered Email IDs.
  3. then add ([email protected]) or where your wordpress hosted. ie ([email protected]) . then submit, it takes few minute to activate wait 15minute to 1 hour depending to your hosting provider, then it will work.
  1. 登录您的 Cpanel。
  2. 转到电子邮件部分 > 然后单击已注册的电子邮件 ID。
  3. 然后添加 ([email protected]) 或您的 wordpress 托管位置。即([email protected])。然后提交,激活需要几分钟时间,等待 15 分钟到 1 小时,具体取决于您的托管服务提供商,然后它将起作用。