sendmail工作但PHP mail()失败了

时间:2022-09-17 07:52:33

I cant seem to send an email using PHP's mail(). I have also tried PHPMailer and Swiftmail with no success. However, the following command on the server delivers mail successfully.

我似乎无法使用PHP的邮件()发送电子邮件。我也试过PHPMailer和Swiftmail没有成功。但是,服务器上的以下命令成功传递邮件。

cat test.txt | mail -s "test mail" my@email.com 

Is there a way to trace where the problem is coming from? mail() just seems to return true or false.

有没有办法追踪问题的来源? mail()似乎只返回true或false。

2 个解决方案

#1


0  

On PHP >= 5.2, there's error_get_last() to retreive whatever error was returned by the last function call. There's details on how to get equivalent information from older versions of PHP on the linked page.

在PHP> = 5.2时,有一个error_get_last()来检索最后一个函数调用返回的错误。有关如何在链接页面上从旧版本的PHP获取等效信息的详细信息。

As for PHPMailer, there's the $mailer->ErrorInfo property which contains the last error occured. SwiftMailer must have something similar. Most likely if mail's working from the command line but not from within PHP or the mailing libraries, there's a misconfiguration at play. I'm guessing your host doesn't have the PHP sendmail_path ini parameter configured.

对于PHPMailer,有$ mailer-> ErrorInfo属性,其中包含发生的最后一个错误。 SwiftMailer必须有类似的东西。最有可能的是,如果邮件是从命令行运行而不是从PHP或邮件库中运行,那么就会出现配置错误。我猜你的主机没有配置PHP sendmail_path ini参数。

#2


0  

Enable all errors, warnings and notices with error_reporting(E_ALL). Have the errors go somewhere useful or register a callback which does some useful stuff.

使用error_reporting(E_ALL)启用所有错误,警告和通知。让错误在某个地方有用或注册一个回调,它会做一些有用的东西。

Then you'll see what's happening. PHP error handling is useless by default (and its defaults are different everywhere so you have to override it in practice).

然后你会看到发生了什么。默认情况下,PHP错误处理是无用的(并且它的默认值在任何地方都是不同的,所以你必须在实践中覆盖它)。

In all likelihood it's configured to do SMTP to localhost, which your MTA does not allow relaying from. Change its config to use sendmail instead, or fix your MTA to allow relaying from localhost.

很可能它被配置为对本地主机执行SMTP,而您的MTA不允许从中继。将其配置更改为使用sendmail,或修复您的MTA以允许从localhost中继。

#1


0  

On PHP >= 5.2, there's error_get_last() to retreive whatever error was returned by the last function call. There's details on how to get equivalent information from older versions of PHP on the linked page.

在PHP> = 5.2时,有一个error_get_last()来检索最后一个函数调用返回的错误。有关如何在链接页面上从旧版本的PHP获取等效信息的详细信息。

As for PHPMailer, there's the $mailer->ErrorInfo property which contains the last error occured. SwiftMailer must have something similar. Most likely if mail's working from the command line but not from within PHP or the mailing libraries, there's a misconfiguration at play. I'm guessing your host doesn't have the PHP sendmail_path ini parameter configured.

对于PHPMailer,有$ mailer-> ErrorInfo属性,其中包含发生的最后一个错误。 SwiftMailer必须有类似的东西。最有可能的是,如果邮件是从命令行运行而不是从PHP或邮件库中运行,那么就会出现配置错误。我猜你的主机没有配置PHP sendmail_path ini参数。

#2


0  

Enable all errors, warnings and notices with error_reporting(E_ALL). Have the errors go somewhere useful or register a callback which does some useful stuff.

使用error_reporting(E_ALL)启用所有错误,警告和通知。让错误在某个地方有用或注册一个回调,它会做一些有用的东西。

Then you'll see what's happening. PHP error handling is useless by default (and its defaults are different everywhere so you have to override it in practice).

然后你会看到发生了什么。默认情况下,PHP错误处理是无用的(并且它的默认值在任何地方都是不同的,所以你必须在实践中覆盖它)。

In all likelihood it's configured to do SMTP to localhost, which your MTA does not allow relaying from. Change its config to use sendmail instead, or fix your MTA to allow relaying from localhost.

很可能它被配置为对本地主机执行SMTP,而您的MTA不允许从中继。将其配置更改为使用sendmail,或修复您的MTA以允许从localhost中继。