php 邮件:无法打开流:权限被拒绝?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1906403/
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 04:15:33  来源:igfitidea点击:

mail: failed to open stream: Permission denied?

phpemailsendmailssmtp

提问by The Disintegrator

I get this warning sending mails with php Warning: mail(1) [function.mail]: failed to open stream: Permission denied in /home/...

我在使用 php 发送邮件时收到此警告警告:mail(1) [function.mail]: failed to open stream: Permission denied in /home/...

  • using ssmtp and gmail as smtp
  • PHP 5.3.1
  • nothing in the logs (no errors)
  • the mail gets to destination
  • the permissions of the files are rwxrxrx
  • 使用 ssmtp 和 gmail 作为 smtp
  • PHP 5.3.1
  • 日志中没有任何内容(没有错误)
  • 邮件到达目的地
  • 文件的权限是 rwxrxrx

Permission denied to what?

什么权限被拒绝?

Even calling something as simple as

甚至调用一些简单的东西

mail("[email protected]", "subject", "body");

邮件(“[email protected]”,“主题”,“正文”);

I still getting this warning

我仍然收到此警告

采纳答案by The Disintegrator

It turns out to be a file permissions problems after all. But not in the scripts, but in the directory. I ran a chmod -R 777 *and the warning went of. upon further examination I found a file called 1, and this file contained a log of the sent mails. The warning was php telling me that he was unable to open this file

原来是文件权限问题。但不是在脚本中,而是在目录中。我跑了chmod -R 777 *,警告消失了。经过进一步检查,我发现了一个名为 的文件1,该文件包含已发送邮件的日志。警告是 php 告诉我他无法打开这个文件

Solution:

解决方案:

 sudo chmod -R 755 *
 sudo chmod  777 1

F#$%^% cryptic php error messages

F#$%^% 神秘的 php 错误信息

回答by Packet Tracer

The problem is that the webserver user is not able to write and/or read the mail log file. For a propper configuration:

问题是网络服务器用户无法写入和/或读取邮件日志文件。对于适当的配置:

1) create the folder and the file for the email logging. For example:

1) 创建用于电子邮件日志记录的文件夹和文件。例如:

touch /var/log/php5/mail.log

2) set the logging file in php.ini:

2)在php.ini中设置日志文件:

mail.log = /var/log/php5/mail.log

3) set the owner and the group for that folder/file in case needed:

3)在需要时为该文件夹/文件设置所有者和组:

check the owner and the group with

检查所有者和组

ls -la /var/log/php5

in case needed, change the group (change www-data for whatever your web server's group is)

如果需要,请更改组(无论您的 Web 服务器的组是什么,更改 www-data)

sudo chgrp -R www-data /var/log/php5

in case needed, change the owner (change www-data for whatever your web server's user is)

如果需要,请更改所有者(无论您的 Web 服务器的用户是什么,更改 www-data)

sudo chown -R www-data /var/log/php5

回答by easement

Does it work if you simplify it?

如果你简化它,它会起作用吗?

 $mail_sent = mail('[email protected]', 'subject', 'message');

If it does, then you know that mail works.

如果是这样,那么您就知道邮件有效。

After that, I would remove the $eol stuff and see if that fixes it. If not, then I would remove the header block and keep removing stuff until it starts working.

在那之后,我会删除 $eol 的东西,看看是否能解决它。如果没有,那么我将删除标题块并继续删除内容,直到它开始工作。