Relaying not allowed message when sending mail with PHP function

穿精又带淫゛_ 提交于 2019-12-20 07:14:05

问题


I'm using wamp server and trying to send email with the PHP function mail('me@ISPdomain.com','my subject','my body'); ,
with the following settings in php.ini:

SMTP = 'ISP's SMTP server'  
smtp_port = 25 

But I get the message:

Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Relaying not allowed. Please use SMTP Authentication.

How can this be solved?


回答1:


Your ISP's mail servers do not allow "relaying", which is a good thing as otherwise they would end up moving a lot of spam.

http://en.wikipedia.org/wiki/Open_mail_relay

An open mail relay is an SMTP server configured in such a way that it allows anyone on the Internet to send e-mail through it, not just mail destined to or originating from known users. This used to be the default configuration in many mail servers; indeed, it was the way the Internet was initially set up, but open mail relays have become unpopular due to their exploitation by spammers and worms. Many relays were closed, or were placed on blacklists by other servers.

To be able to utilize your ISP's mail servers you need to authenticate first with a username and password.

You can try a hack of that php.ini line that goes like this:

SMTP = 'username:password@ISP's SMTP server address'

This is not guaranteed to work as this option requires a non-standard modification or option to be set on the mail server.

Your other option is to simply run your own local proxy mail server that requires no authentication, which will then either send the mail directly to the recipient's mail server, or via an authenticated connection to your mail server.

I don't know what is recommended to be used with WampServer, but with WampDeveloper Pro the recommended local mail servers are:

  1. hmailserver
  2. mailenable
  3. Smartermail

You should see the features and requirements of each one. I believe one of them can interfere with MySQL (as the installer will try to place its own copy of it).




回答2:


The ISPdomain.com SMTP server is probably complaining that your connection is too basic for its anti-spam rules.




回答3:


As the error message says, you need to use SMTP authentication for that server.

This is not possible using PHP's built-in SMTP capabilities.

The easiest way is to use a pre-made mailer class like Swiftmailer. Here is an example how to do it.



来源:https://stackoverflow.com/questions/6096449/relaying-not-allowed-message-when-sending-mail-with-php-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!