Home » Php » php – Warning: mail() [function.mail]: SMTP server response: 553 We do not relay non-local mail, sorry

php – Warning: mail() [function.mail]: SMTP server response: 553 We do not relay non-local mail, sorry

Posted by: admin July 12, 2020 Leave a comment

Questions:

The following script sends email using mail function . But i am unable to send an email.Upon clicking submit this gets displayed :

Warning: mail() [function.mail]: SMTP server response: 553 We do not relay non-local mail, sorry. in E:\xampp\htdocs\feedback.php on line 19
mail sent successfully

SCRIPT

<?php 
if( isset( $_REQUEST['email'] ) ) {
    $email = $_REQUEST['email'];
    $subject = $_REQUEST['subject'];
    $message = $_REQUEST['message'];
    mail("[email protected]" , $subject , $message , "From:".$email );
    echo "mail sent successfully";
}  else {
     echo "<form method = 'post' action = 'feedback.php'>
     Email of sender : <input name = 'email' type = 'text' /> <br/>
     Subject : <input name = 'subject' type = 'text'/> <br/>
     Enter your feedback here : <textarea name = 'message' rows = 15 cols = 40 > </textarea> <br/>
     <input type = 'submit'/>
     </form>";
   }
?>

I am using Apache as php server

Also tell why we have to write $subject , $message i.e with the $ sign in the mail argument , since we have declared $email , $message etc. , just above. Why can’t we just write message , email , .. without the dollar sign?

How to&Answers:
  1. You’re using XAMPP which by default comes with Mercury, which is not configured to send mail to a different server by default. It is basically there for debugging. Instructions do exist to configure it to do so, but Windows + Apache is generally best only as a debugging environment in my experience.

  2. PHP variables all have the $ before them. It’s called a sigil. It is what distinguishes them from, say, constants, class definitions, and functions. If you want to assign a value and then send it into a function, you need to use variables. You can use define to set a constant if it is important enough, but trust me, those situations are rare and you should generally avoid them.

You can also do this, however:

mail("[email protected]" , 
      $_REQUEST['subject'] , 
      $_REQUEST['message'] , 
      "From:".$_REQUEST['email'] );

Answer:

Resolvendo:
In Xampp menu,
Go to mercury admin–>Configuration menu–>MercuryS SMTP Server–>Connection control. In that window, remove the check on the checkbox. See below:

enter image description here

Then in php.ini file:

[mail function] SMTP=127.0.0.1 <——————change localhost to ip local

smtp_port=25

Answer:

Warning: mail() [function.mail]: SMTP server response: 553 We do not relay non-local mail, sorry. in E:\xampp\htdocs\feedback.php on line 19
mail sent successfully

That means your server is not properly configured. It should be able to send mails through some smarthost which allows relaying from your system. On a real server this is likely to be the MTA running on localhost.

Also tell why we have to write $subject , $message i.e with the $ sign in the mail argument , since we have declared $email , $message etc. , just above. Why can’t we just write message , email , .. without the dollar sign?

That’s because variables are prefixed with $ in PHP.

Answer:

The following script sends email using mail function . But i am unable to send an email.Upon clicking submit this gets displayed :

The SMTP server prevents sending mail through it when not from local machine / domain.

This is to prevent spammers using the SMTP server to send mail. (open relay).

_Also tell why we have to write $subject , $message i.e with the $ sign in the mail argument , since we have declared $email , $message etc. , just above. Why can’t we just write message , email , .. without the dollar sign _ ?


You don’t have to use variables.

mail('[email protected]' , 'subject', 'test', 'From: [email protected]');

is perfectly fine

.

You could have also done:

mail("[email protected]" , 
      $_REQUEST['subject'] , 
      $_REQUEST['message'] , 
      "From:".$_REQUEST['email'] );

Answer:

This issue is due to your server configuraton.
Now a days server stops open relaying the messages and method we are using in core PHP for sending mail is an open relay method.Stopping open relay reduces spamming.
Thats the reson you are getting this error message,try mailing library like swift mail for sending mails from your SMTP

Answer:

If you are using Windows + Xampp installation:
This is because mercury service is already running and it is unable to send email outside the localhost.
Go to xammp control panel and stop the mercury service. Hope it helps.

Answer:

Answer is simple: your SMTP server does not support relayed messages. You might need to configure or login to it for relaying to work. Although I have done something similar before I cannot give any sample for now. Try searching “SMTP login in PHP”