Home >CMS Tutorial >WordPress >Solve the problem of 'Your host has disabled the Mail function' when sending emails in WordPress

Solve the problem of 'Your host has disabled the Mail function' when sending emails in WordPress

藏色散人
藏色散人forward
2021-01-04 14:18:333675browse

The following column WordPress Tutorial will introduce to you how to solve the problem of "Your host has disabled the Mail function" when sending emails in WordPress. I hope it will be helpful to friends in need!

Solve the problem of 'Your host has disabled the Mail function' when sending emails in WordPress

Specific problem situation

I recently discovered a very interesting phenomenon when searching for topic bugs, which is the problem of SMTP mailbox settings. , comment replies can be sent abnormally, but there is no prompt for review. When retrieving via email, the following error appears:

Unable to send email.

Possible reason: Your host has disabled the mail() function.

Detect whether the mail function is disabled

Use a PHP probe to detect whether the host provider has disabled the mail function.

The PHP probe code is as follows. Save it as a php file and upload it to the server to open it to test it:

 <!--?php if (function_exists(&#39;mail&#39;)) { echo "支持mail()函数!"; } else echo "不支持mail()函数!"; ?-->

Solution

Originally thought it was a balance The mail() function was disabled on the Tian host, but it was found through the PHP probe that it was not disabled.

The following provides solutions to the problem that the mail function is disabled despite both disabling and supporting mail functions. This is a personal experience. Don’t let anyone stumble here again.

Solution to host disabling mail function

Through the above PHP probe, if it is found that the host has disabled mail function, directly use SMTP to send mail instead of the original mail function

Submit the SMTP mailbox setting code used here (the example is blog mailbox setting) and throw it into functions.php.

 function mail_smtp( $phpmailer ){
  $phpmailer->From = “lijie@php2.cc”; //发件人
  $phpmailer->FromName = “PHP二次开发”; //发件人昵称
  $phpmailer->Host = “smtp.ym.163.com”; //SMTP服务器地址
  $phpmailer->Port = 25; //SMTP端口,常用的有25、465、587,具体谷歌百度
  $phpmailer->SMTPSecure = “”; //SMTP加密方式,常用的有SSL/TLS,具体谷歌百度
  $phpmailer->Username = “lijie@php2.cc”; //邮箱帐号
  $phpmailer->Password = *; //邮箱密码(缙哥哥就用星号代替了)
  $phpmailer->IsSMTP(); //使用SMTP发送
  $phpmailer->SMTPAuth = true; //启用SMTPAuth服务
  }
  add_action(‘phpmailer_init’,’mail_smtp’);

The host supports the mail function solution

If the test supports the mail function, look below:

Since I only had the test administrator’s email address before, I later tried to register a new user , using the function of retrieving the password via email, the email was sent normally without any surprises.

Next, I changed the SMTP email account to 163 and used the administrator email to retrieve the password. The result was received normally without any surprise.

Finally, it was clear. It turns out that the receiving email address and the sending email address cannot be the same. This result surprised me. It actually appeared in such a small link. I thought it was a theme problem and changed the code several times. Sorry, but it also fixed a major BUG. Tossing, why bother tossing if you are young?

But having said that, since I changed my 163 mailbox, I have received a lot of review, comment replies, and registration email reminders. Is it annoying? I might as well do it separately. An administrator's mailbox is used as the outgoing mailbox, which can effectively reduce the number of emails received, and now the ears are quiet.

The above is the detailed content of Solve the problem of 'Your host has disabled the Mail function' when sending emails in WordPress. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete