简体   繁体   English

无论如何绕过错误:无法在“ localhost”端口25上连接到邮件服务器

[英]Anyway to bypass the error: Failed to connect to mailserver at “localhost” port 25

I get the following error from my php scripts on certain wifi networks: 我从某些wifi网络上的php脚本中收到以下错误:

Message: 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() 消息:mail()[function.mail]:无法通过“ localhost”端口25连接到邮件服务器,无法验证php.ini中的“ SMTP”和“ smtp_port”设置或使用ini_set()

I fully understand the error, and realise it's dependant on which internet connection I'm on and their SMTP/port 25 set up. 我完全理解该错误,并意识到它取决于我所连接的Internet连接及其SMTP /端口25的设置。

The thing is I'm backpacking around the world and never know what connection I'm going to be on, so ideally, if smtp isn't available on port 25, I just want my code to bypass it and carry on - not error on mail() - I don't care if it doesn't send the email - I just want my pages to load! 问题是我在世界各地背包旅行,却永远不知道要建立什么样的连接,因此理想情况下,如果端口25上没有smtp,我只希望代码绕过它并继续进行-不会出错在mail()上-我不在乎它是否不发送电子邮件-我只想加载我的页面!

The best solution I have come up so far is to have php code like this and uncomment when needed: 到目前为止,我提出的最好的解决方案是拥有这样的php代码,并在需要时取消注释:

//if (1==1) {
if (mail($to, $subject, $emailConfirmationHTML, $headers)) {

Is there anything else I can put in the php - or the apache set up to help me out? 还有什么我可以放入php-或设置为帮助我的apache吗?

i think the simple solution would be to wrap the statement in a try catch block, handle the exception and carry on. 我认为简单的解决方案是将语句包装在try catch块中,处理异常并继续。
ideally though if you want to be able to send mail from anywhere, you should look around for a mail relay, do a google search for "MAIL RELAY" and you will see a number of services you can use. 理想情况下,尽管如果您希望能够从任何地方发送邮件,则应该四处寻找邮件中继,在Google上搜索“ MAIL RELAY”,然后您会看到许多可以使用的服务。

you can config your smtp server to listen on any ip addresses your system has. 您可以配置您的smtp服务器以侦听系统具有的任何IP地址。 in most cases sendmail is the choice. 在大多数情况下,sendmail是选择。

this configuration in sendmail will help you: sendmail中的此配置将帮助您:

SMTP daemon options SMTP守护程序选项

O DaemonPortOptions=Port=smtp,Addr=0.0.0.0, Name=MTA O DaemonPortOptions =端口= smtp,地址= 0.0.0.0,名称= MTA

modify your /etc/mail/sendmail.cf (or wherever it is) and set the Addr in SMTP daemon options to 0.0.0.0 修改您的/etc/mail/sendmail.cf(或无论在哪里)并将SMTP守护程序中的Addr选项设置为0.0.0.0

Regards, MAGMAG 问候,MAGMAG

暂无
暂无

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

相关问题 无法通过“localhost”端口 25 连接到邮件服务器 - Failed to connect to mailserver at "localhost" port 25 无法连接到“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上的邮件服务器,验证您的“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