为什么mail()PHP函数不能与WAMP默认安装一起使用? [英] Why mail() PHP function does not work with WAMP default installation?
问题描述
我正在尝试使用这个简单的脚本发送电子邮件:
<?php
if(mail('my_email@gmail.com','My Title','Some Text')){
echoOK;
} else {
echoWhy ??;
}
?>
不幸的是,我收到以下警告:
警告:mail()[function.mail]:无法在localhost端口25连接到mailserver,验证php.ini中的SMTP和smtp_port设置或在C中使用ini_set() \My_Path\send_email.php第3行
为什么?
可能是什么原因?
我希望发送电子邮件是一个非常简单的任务...:(
为了能够发送电子邮件,您需要一个外发电子邮件服务器(MTA),在大多数Linux系统中,默认情况下存在一个,PHP将通过向邮件发送邮件来使用它,一个Linux应用程序/别名,用于将邮件提交给您拥有的MTA
默认情况下,Windows不包含MTA。在Windows中,为了能够从PHP发送邮件,您需要访问一些传出的电子邮件服务器,并告知PHP的地址和端口,这是在php.ini中使用 SMTP
和 smtp_port
设置。端口 25
将默认为 localhost
。除非您自己在该机器上设置了邮件服务器,否则这将失败。
如果您的ISP为您提供外发邮件服务器,例如,您可以使用其地址和端口号。或者,如果您认真发送邮件,您可以在本地计算机或本地网络的某个地方设置自己的邮件服务器。
I have a default installation of WAMP Server 2.0.
I'm trying to send email using this simple script:
<?php
if (mail('my_email@gmail.com', 'My Title', 'Some Text')) {
echo "OK";
} else {
echo "Why ??";
}
?>
Unfortunately, I get the following warning:
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\My_Path\send_email.php on line 3 Why ??
What could be the reason for that ?
I expected sending email to be a very simple task ... :(
To be able to send email you need an outgoing email server (MTA). In most Linux systems there exists one by default, and PHP will use it by submitting mail to sendmail, a Linux app/alias for submitting mail to whichever MTA you have installed.
Windows doesn't include an MTA by default. In Windows, to be able to send mail from PHP you need to have access to some outgoing email server and tell PHP the address and port of it. This is done in php.ini using the SMTP
and smtp_port
settings. It will default to localhost
on port 25
. Unless you have set up a mail server on that machine yourself, this will fail.
If your ISP gives you an outgoing mail server, for example, you could use its address and port number. Or, if you're serious about sending mail, you'd set up your own mail server on the local machine or somewhere in your local network.
这篇关于为什么mail()PHP函数不能与WAMP默认安装一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!