简体   繁体   English

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

[英]Failed to connect to mailserver at "localhost" port 25

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 = you@yoursite.com

I'm using my laptop as a server.. What am I doing wrong?我使用我的笔记本电脑作为服务器..我做错了什么? Thanks.谢谢。

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.如果是 Unix,则启用 sendmail 如果是 Windows,请安装 IIs 的 Simple Mail Transfer Server(不确定名称是否正确)组件。 Eg for windows 2003 follow this: http://msdn.microsoft.com/en-us/library/8b83ac7t.aspx例如,对于 Windows 2003,请按照以下步骤操作: http : //msdn.microsoft.com/en-us/library/8b83ac7t.aspx

For sending mails using php mail function is used.使用 php 邮件功能发送邮件。 But mail function requires SMTP server for sending emails.但是邮件功能需要 SMTP 服务器来发送电子邮件。 we need to mention SMTP host and SMTP port in php.ini file.我们需要在 php.ini 文件中提及 SMTP 主机和 SMTP 端口。 Upon successful configuration of SMTP server mails will be sent successfully sent through php scripts.成功配置 SMTP 服务器后,邮件将通过 php 脚本成功发送。

On windows, nearly all AMPP (Apache,MySQL,PHP,PHPmyAdmin) packages don't include a mail server (but nearly all naked linuxes do have!).在 Windows 上,几乎所有的 AMPP(Apache、MySQL、PHP、PHPmyAdmin)包都不包含邮件服务器(但几乎所有裸 linux 都有!)。 So, when using PHP under windows, you need to setup a mail server!所以,在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). SMTP4Dev 是一个简单的单文件邮件服务器工具,它确实收集它发送的邮件(因此它并不真正发送邮件,它只是保留它们以供开发)。 Perfect tool.完美的工具。

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.如果您仅在本地主机上运行您的应用程序并且它尚未上线,我相信使用它发送邮件是非常困难的。

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.ini during run time.但我认为ini_set()可以帮助您在运行时更改php.ini中的值。

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.首先,您不会被迫在本地主机上使用 SMTP,如果您将本地主机条目更改为来自您的 ISP 提供商(谁会让您中继邮件)的 MTA 的 DNS 名称,它将立即工作,所以没有搞乱你自己的电子邮件服务。 Just try to use your providers SMTP servers, it will work right away.只需尝试使用您的提供商的 SMTP 服务器,它就会立即工作。

PHP mail function can send email in 2 scenarios: PHP 邮件功能可以在 2 种情况下发送电子邮件:

a.一个。 Try to send email via unix sendmail program 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 的主机/端口/用户名/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.如果 php 无法连接到电子邮件服务器,它将发出警告(并且您在日志中看到此类工作)要解决它,请在本地计算机上安装 smtp 服务器或使用任何可用的服务器。 How to setup / configure smtp you can find on php.net如何设置/配置 smtp,您可以在 php.net 上找到

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

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. php不允许或认为从本地主机发送电子邮件非常困难,但是如果将项目上传到服务器,则可以解决此问题。 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. 如果要检查本地服务器上是否发送了电子邮件,则必须下载smtp4dev并安装并运行它。 This will give you a message if your email sent successfully or there is an issue with your code. 如果您的电子邮件发送成功或代码有问题,这会给您一条消息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法连接到“localhost”端口25上的邮件服务器 - Failed to connect to mailserver at “localhost” port 25 如何解决“无法通过“ localhost”端口25连接到邮件服务器” - how to solve the “Failed to connect to mailserver at ”localhost“ port 25” 无论如何绕过错误:无法在“ localhost”端口25上连接到邮件服务器 - Anyway to bypass the error: Failed to connect to mailserver at “localhost” port 25 无法连接到“localhost”端口25上的邮件服务器,验证您的“SMTP” - Failed to connect to mailserver at “localhost” port 25, verify your “SMTP” 我更改了SMTP和SMTP端口,但它仍然说无法连接到“localhost”端口25的邮件服务器 - I changed the SMTP and SMTP Port but it still says Failed to connect to mailserver at “localhost” port 25 警告:mail()[function.mail]:无法通过“ localhost”端口25连接到邮件服务器 - Warning: mail() [function.mail]: Failed to connect to mailserver at “localhost” port 25 mail():无法在“localhost”端口 25 连接到邮件服务器,请验证 php.ini 中的“SMTP”和“smtp_port”设置 - mail(): Failed to connect to mailserver at “localhost” port 25, verify your “SMTP” and “smtp_port” setting in php.ini 警告:mail()[function.mail]:无法连接到“localhost”端口25的邮件服务器,验证你的“SMTP”和“smtp_port”,XAMPP for WIndows XP - Warning: mail() [function.mail]: Failed to connect to mailserver at “localhost” port 25, verify your “SMTP” and “smtp_port”, XAMPP for WIndows XP 无法连接到本地主机的邮件服务器 - failed to connect to mailserver at localhost 警告:mail():无法连接到“localhost”端口25上的邮件服务器,验证php.ini中的“SMTP”和“smtp_port”设置或使用ini_set() - Warning: mail(): Failed to connect to mailserver at “localhost” port 25, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM