Relaying not allowed message when sending mail with PHP function

Ash picture Ash · May 23, 2011 · Viewed 7k times · Source

I'm using wamp server and trying to send email with the PHP function mail('[email protected]','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?

Answer

rightstuff picture rightstuff · May 23, 2011

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).