PHP mail problem

2019-05-31 01:27发布

I am trying to implement a password reset functionality on my company website where if a user needs to reset her password, she can click on a link and a new, randomly generated password will be sent to her inbox.

I am using the PHP mail() function. Now, I am running PHP5 on an Ubuntu machine. In php.ini I have declared SMTP as the IP of the machine running the mail server and smtp_port as 25. Further, I have tried to telnet into the mailserver on port 25 and send a mail - it works (my work terminal is Windows).

The problem is that the mail is not being sent / received - the PHP script calling mail() hangs for about 1 minute at the end of which mail() returns true.

The worst part is that I am out of ideas on how to even find out where the problem lies - with PHP, with Ubuntu, with the mailserver or with the code!

Can somebody please help?

标签: php smtp
7条回答
兄弟一词,经得起流年.
2楼-- · 2019-05-31 01:49

Your ISP may be the problem. Port 25 is frequently blocked by ISPs in order to prevent mass spamming. Try changing to a non-standard port and see if that helps.

Edit: And here is something detailing the issue (although their solution is to relay to the ISP mail server, not change ports).

查看更多
看我几分像从前
3楼-- · 2019-05-31 01:50

Try to send an email with mail program from shell. First see if that works.

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-05-31 01:51

I haven't looked in php.ini recently, but doesn't it say:

[mail function]
; For Win32 only.
;SMTP =

Emphasis on the For Win32 only.

You may want to look at PEAR::Mail instead. When pear.php.net is actually responding, that is.

查看更多
倾城 Initia
5楼-- · 2019-05-31 02:01

It is also possible to bypass the mail() function of php by using a mail library. For example SwiftMailer (http://swiftmailer.org/) This is a really good class for safely sending e-mails (plain/html).

With this class you are able to connect directly to an SMTP server and so bypassing the server configuration.

查看更多
爱情/是我丢掉的垃圾
6楼-- · 2019-05-31 02:03

Can you check your mail.err and mail.log files ?

查看更多
做自己的国王
7楼-- · 2019-05-31 02:07

You need the Zend Framework SMTP mail class for example because this stupid braindead php implementation does not work with SMTP ports on Unix.

Please subscribe to the PHP Core mailing list and complain about it - maybe they change it if more and more people are coming in and they see that not everyone what sendmail.

查看更多
登录 后发表回答