SMTP server response: 550 5.7.1 Unable to relay in

2019-05-09 11:07发布

Here is my code:

<?php
mail('myemail@gmail.com','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:

[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 = no-reply@mycompany.com

Even have the site set up in IIS7:

Any ideas?

标签: php smtp
2条回答
贪生不怕死
2楼-- · 2019-05-09 11:24

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)

查看更多
冷血范
3楼-- · 2019-05-09 11:27

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.

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 msmtp or 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_path accordingly.
  • Change the mail server's configuration to allow relaying mail from the web server's IP address.
查看更多
登录 后发表回答