php 警告:mail() [function.mail]:SMTP 服务器响应:553 我们不转发非本地邮件,抱歉
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6809369/
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
Warning: mail() [function.mail]: SMTP server response: 553 We do not relay non-local mail, sorry
提问by Suhail Gupta
The following script sends email using mail
function . But i am unable to send an email.Upon clicking submit
this gets displayed :
以下脚本使用mail
函数发送电子邮件。但我无法发送电子邮件。点击后submit
显示:
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
我使用 Apache 作为 php 服务器
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?
还要说明为什么我们必须写$subject
,$message
即$
在邮件参数中使用符号,因为我们已经声明$email
,$message
等等,就在上面。为什么我们不能在没有美元符号的情况下写消息、电子邮件、..?
采纳答案by cwallenpoole
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 existto configure it to do so, but Windows + Apache is generally best only as a debugging environment in my experience.
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 usedefine
to set a constant if it is important enough, but trust me, those situations are rare and you should generally avoid them.
您使用的是默认情况下随 Mercury 一起提供的 XAMPP,默认情况下它没有配置为将邮件发送到不同的服务器。它基本上用于调试。确实存在配置它的说明,但根据我的经验,Windows + Apache 通常最好仅作为调试环境。
PHP 变量前面都有 $。它被称为
sigil
. 这是它们区别于常量、类定义和函数的地方。如果要赋值,然后将其发送到函数中,则需要使用变量。define
如果足够重要,您可以使用来设置常量,但相信我,这些情况很少见,您通常应该避免它们。
You can also do this, however:
但是,您也可以这样做:
mail("[email protected]" ,
$_REQUEST['subject'] ,
$_REQUEST['message'] ,
"From:".$_REQUEST['email'] );
回答by Filipe Souza
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:
解决方法:在Xampp菜单中,
进入mercury admin-->Configuration菜单-->MercuryS SMTP Server-->Connection control。在该窗口中,取消选中复选框。见下文:
Then in php.ini file:
然后在 php.ini 文件中:
[mail function] SMTP=127.0.0.1 <------------------change localhost to ip local
[邮件功能] SMTP=127.0.0.1 <-------------------将localhost改成ip local
smtp_port=25
smtp_port=25
回答by ThiefMaster
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
警告:mail() [function.mail]:SMTP 服务器响应:553 我们不转发非本地邮件,抱歉。在E:\xampp\htdocs\feedback.php第19行邮件发送成功
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.
这意味着您的服务器没有正确配置。它应该能够通过一些允许从您的系统中继的智能主机发送邮件。在真实服务器上,这可能是在localhost 上运行的 MTA 。
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?
还要说明为什么我们必须写 $subject , $message ,即在邮件参数中带有 $ 符号,因为我们已经声明了 $email , $message 等,就在上面。为什么我们不能在没有美元符号的情况下写消息、电子邮件、..?
That's because variables are prefixed with $
in PHP.
那是因为变量$
在 PHP中以 为前缀。
回答by PeeHaa
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.
当不是来自本地机器/域时,SMTP 服务器会阻止通过它发送邮件。
This is to prevent spammers using the SMTP server to send mail. (open relay).
这是为了防止垃圾邮件发送者使用 SMTP 服务器发送邮件。(打开继电器)。
_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 _ ?
_还要说明为什么我们必须写 $subject , $message ,即在邮件参数中使用 $ 符号,因为我们已经声明了 $email , $message 等,就在上面。为什么我们不能在没有美元符号 _ 的情况下写消息、电子邮件、..?
You don't have to use variables.
您不必使用变量。
mail('[email protected]' , 'subject', 'test', 'From: [email protected]');
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'] );
回答by sammeer
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
此问题是由于您的服务器配置造成的。现在,服务器停止开放中继我们在核心 PHP 中用于发送邮件的消息和方法是开放中继方法。停止开放中继可以减少垃圾邮件。这就是您收到此错误消息的原因,请尝试使用 swift mail 之类的邮件库从您的 SMTP 发送邮件
回答by Vamshi
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.
如果您使用的是 Windows + Xampp 安装:这是因为 Mercury 服务已经在运行,并且无法在 localhost 之外发送电子邮件。转到 xampp 控制面板并停止 Mercury 服务。希望能帮助到你。
回答by Cem Kalyoncu
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"
答案很简单:您的 SMTP 服务器不支持中继消息。您可能需要配置或登录它才能中继工作。虽然我之前做过类似的事情,但现在不能给出任何样本。尝试搜索“PHP 中的 SMTP 登录”