php SMTP 服务器响应:550 5.7.1 无法中继 - 向非公司地址发送电子邮件

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

SMTP server response: 550 5.7.1 Unable to relay in - Sending email to a non-company address

phpsmtp

提问by etm124

Here is my code:

这是我的代码:

<?php
mail('[email protected]','Test','Test');
?>

When sending to a non-company address, I get the following error:

发送到非公司地址时,出现以下错误:

Warning: mail(): SMTP server response: 550 5.7.1 Unable to relay in C:\inetpub\wwwroot\internal_tools\include\mail.php on line 2

When switching the email address to my work email, it works just fine. My PHP.ini looks fine, too:

将电子邮件地址切换到我的工作电子邮件时,效果很好。我的 PHP.ini 看起来也不错:

[mail function]
; For Win32 only.
; http://php.net/smtp
;SMTP = localhost
SMTP = PCMAIL1.mycompany.com
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = [email protected]

Even have the site set up in IIS7:

甚至在 IIS7 中设置了站点:

Any ideas?

有任何想法吗?

回答by PleaseStand

To prevent abuse for sending spam, many email servers require that the client be authenticated as a legitimate user before relaying mail (forwarding it to the recipient's email server). You have specified credentials in IIS; however, PHP does not make use of them.

为了防止滥用发送垃圾邮件,许多电子邮件服务器要求在中继邮件(将其转发到收件人的电子邮件服务器)之前将客户端验证为合法用户。您已在 IIS 中指定凭据;但是,PHP 不使用它们。

Here are your options:

以下是您的选择:

  • Instead of the mail()function, use one of the existing PHP mailer libraries that supports SMTP authentication (PEAR Mail, phpmailer, Swift Mailer, etc.).
  • Install and configure msmtpor one of the alternatives (here's how to make msmtp work with PHP). PHP will execute the program, which does support SMTP authentication, whenever it has to send a message if you set sendmail_pathaccordingly.
  • Change the mail server's configuration to allow relaying mail from the web server's IP address.
  • mail()使用支持 SMTP 身份验证的现有 PHP 邮件程序库之一(PEAR Mail、phpmailer、Swift Mailer)代替该函数。
  • 安装和配置msmtp或其中一种替代方法(这是使 msmtp 与 PHP 一起工作的方法)。PHP 将执行该程序,该程序支持 SMTP 身份验证,只要您进行了相应设置,它就必须发送消息sendmail_path
  • 更改邮件服务器的配置以允许从 Web 服务器的 IP 地址中继邮件。

回答by David SK

You need to check your Smtp provider's policy. Or you need to check your Smtp server configuration (if this server deliver the emails directly)

您需要检查您的 Smtp 提供商的政策。或者您需要检查您的 Smtp 服务器配置(如果此服务器直接发送电子邮件)