dsfasdfsda234234 2010-09-10 11:00
浏览 202
已采纳

使用套接字的PHP SMTP服务器:连接被拒绝

In one of my personal project I am developing a basic SMTP server in php. It's ready and working when I launch it on its own from the command line; I access it correctly through telnet and it is responding correctly to SMTP commands and I access it correctly also from a php script sending an email using this server.

Now I have an issue when I launch the server from a php script and not from the command line (I do it using exec function). The server is responding correctly when I access it through telnet but not anymore from a php script sending an email.

Could anyone help me?

Note

To send emails from php scripts I use Mail PEAR extension. When I launch the server from within a script and try to send an email in the same process I get this error:

SMTP: Failed to connect socket: Connection refused (code: -1, response: )

Summary

My server implementation is in server.php and the script sending an email is in mail-test.php.

1) If I launch the server on the command line this way: php server.php and then launch php mail-test.php the script is processed normally and the email is sent. I can also access the server via telnet 127.0.0.1 3535 and communicating with the server normally.

2) Using an another script called test.php I wanted to wrap the server management, launching the server via exec("php server.php > /dev/null 2>&1 &"); and then doing the mail sending from that script in one shot. Doing that way, the server is correctly launched (I can access it via telnet) but emails sent from test.php thus after the server launch raise an error. If I send emails from an another script before killing the test.php process the email is correctly sent however...

I hope I am enough explicit.

  • 写回答

2条回答 默认 最新

  • dongpu6141 2010-09-20 09:21
    关注

    Strangely, I resolved this issue by setting SO_RCVTIMEO this way:

    socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 0, 'usec' => 500))

    The error message I got was not really meaningful.

    I hope that it help others facing similar issue.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装