php 无法通过“localhost”端口 25 连接到邮件服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4532486/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 13:21:12  来源:igfitidea点击:

Failed to connect to mailserver at "localhost" port 25

phpemailsmtp

提问by Loolooii

I keep getting this error when I try to send an e-mail in PHP:

当我尝试用 PHP 发送电子邮件时,我不断收到此错误:

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:\wamp\www\dressoholic\register.php on line 50

my php.ini looks like this:

我的 php.ini 看起来像这样:

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = [email protected]

I'm using my laptop as a server.. What am I doing wrong? Thanks.

我使用我的笔记本电脑作为服务器..我做错了什么?谢谢。

采纳答案by MK.

You need to be running a mail server locally. If this is Unix, enable sendmail If this is Windows install the Simple Mail Transfer Server (not sure if the name is correct) component of IIs. E.g. for windows 2003 follow this: http://msdn.microsoft.com/en-us/library/8b83ac7t.aspx

您需要在本地运行邮件服务器。如果是 Unix,则启用 sendmail 如果是 Windows,请安装 IIs 的 Simple Mail Transfer Server(不确定名称是否正确)组件。例如,对于 Windows 2003,请按照以下步骤操作:http: //msdn.microsoft.com/en-us/library/8b83ac7t.aspx

回答by Rubin Porwal

For sending mails using php mail function is used. But mail function requires SMTP server for sending emails. we need to mention SMTP host and SMTP port in php.ini file. Upon successful configuration of SMTP server mails will be sent successfully sent through php scripts.

使用 php 邮件功能发送邮件。但是邮件功能需要 SMTP 服务器来发送电子邮件。我们需要在 php.ini 文件中提及 SMTP 主机和 SMTP 端口。成功配置 SMTP 服务器后,邮件将通过 php 脚本成功发送。

回答by Sliq

On windows, nearly all AMPP (Apache,MySQL,PHP,PHPmyAdmin) packages don't include a mail server (but nearly all naked linuxes do have!). So, when using PHP under windows, you need to setup a mail server!

在 Windows 上,几乎所有的 AMPP(Apache、MySQL、PHP、PHPmyAdmin)包都不包含邮件服务器(但几乎所有裸 linux 都有!)。所以,在windows下使用PHP时,需要设置一个邮件服务器!

Imo the best and most simple tool ist this: http://smtp4dev.codeplex.com/

我最好和最简单的工具是这个:http: //smtp4dev.codeplex.com/

SMTP4Dev is a simple one-file mail server tool that does collect the mails it send (so it does not really sends mail, it just keeps them for development). Perfect tool.

SMTP4Dev 是一个简单的单文件邮件服务器工具,它确实收集它发送的邮件(因此它并不真正发送邮件,它只是保留它们以供开发)。完美的工具。

回答by NullPoiиteя

If you are running your application just on localhost and it is not yet live, I believe it is very difficult to send mail using this.

如果您仅在 localhost 上运行您的应用程序并且它还没有上线,我相信使用它发送邮件是非常困难的。

Once you put your application online, I believe that this problem should be automatically solved. But i think ini_set()helps you to change the values in php.iniduring run time.

一旦你把你的应用程序放到网上,我相信这个问题应该会自动解决。但我认为ini_set()可以帮助您php.ini在运行时更改值。

回答by Glenn Plas

First of all, you aren't forced to use an SMTP on your localhost, if you change that localhost entry into the DNS name of the MTA from your ISP provider (who will let you relay mail) it will work right away, so no messing about with your own email service. Just try to use your providers SMTP servers, it will work right away.

首先,您不会被迫在本地主机上使用 SMTP,如果您将本地主机条目更改为来自您的 ISP 提供商(谁会让您中继邮件)的 MTA 的 DNS 名称,它将立即工作,所以没有搞乱你自己的电子邮件服务。只需尝试使用您的提供商的 SMTP 服务器,它就会立即工作。

回答by Maxim

PHP mail function can send email in 2 scenarios:

PHP 邮件功能可以在 2 种情况下发送电子邮件:

a. Try to send email via unix sendmailprogram At linux it will exec program "sendmail", put all params to sendmail and that all.

一种。尝试通过 unix sendmail程序发送电子邮件在 linux 中,它将执行程序“sendmail”,将所有参数都放到 sendmail 中。

OR

或者

b. Connect to mail server(using smtp protocol and host/port/username/pass from php.ini) and try to send email.

湾 连接到邮件服务器(使用 smtp 协议和来自 php.ini 的 host/port/username/pass)并尝试发送电子邮件。

If php unable to connect to email server it will give warning (and you see such workning in your logs) To solve it, install smtp server on your local machine or use any available server. How to setup / configure smtp you can find on php.net

如果 php 无法连接到电子邮件服务器,它将发出警告(并且您在日志中看到此类工作)要解决它,请在本地计算机上安装 smtp 服务器或使用任何可用的服务器。如何设置/配置 smtp,您可以在 php.net 上找到

回答by Vinaykumar Chalamalla

Change SMTP=localhost to SMTP=smtp.gmail.com

将 SMTP=localhost 更改为 SMTP=smtp.gmail.com

回答by Bashir ahmad

php doesn't allow or think it as very difficult to send email from localhost but this issue will be solved if you upload the project to the server. and if you want to check if email sent or not on the local server then you have to download smtp4dev and install and run it. This will give you a message if your email sent successfully or there is an issue with your code.

php 不允许或认为从 localhost 发送电子邮件非常困难,但是如果您将项目上传到服务器,这个问题将得到解决。如果您想检查本地服务器上是否发送了电子邮件,则必须下载 smtp4dev 并安装并运行它。如果您的电子邮件发送成功或您的代码有问题,这会给您一条消息。