1

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?

7 Answers 7

3

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I read in a tutorial that linux will also successfully use the SMTP field if sendmail_path is not specified. Is that incorrect?
To my knowledge, it's not correct. In the notes section for the mail command, it even says "The Windows implementation of mail() differs in many ways from the Unix implementation. First, it doesn't use a local binary for composing messages but only operates on direct sockets" which implies that the unix version always uses sendmail.
I will be using PEAR::Mail then. Am leaving for home now (Its 10 in the night here). Will write about it in the morning :)
Swift Mailer would be a better alternative to PEAR::Mail.
1

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

3 Comments

I am absolutely new to Linux. I can't seem to find mail.err and mail.log files :(
The /var/log/ directory usually holds all the logs for most linux distros
mail.err has the following entry: "My unqualified host name (OCR) unknown; sleeping for retry". I do not know what it means.
0

Your email server probably needs authentication ("POP before SMTP" or ASMTP - Authenticated SMTP). Since you've probably recently checked your email from your Windows machine, your IP address will be authenticated and allowed to send email for a short time: from your Ubuntu machine, probably not.

On the Ubuntu machine, see if you can NOT use the IP address of your SMTP server: PHP should work out how to send the email out anyway. Otherwise, you'll have to find out how to authenticate against your email server and implement it into PHP.

2 Comments

No authentication needed. I sent a mail using telnet (Ubuntu) to the mailserver - it worked without authentication.
Ok, try removing the entry in the php.ini file referencing the IP address of the server to see if PHP is able to send the email using sendmail.
0

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

2 Comments

Then it must be the php's configuration. Can you see how the mail function is configured in php.ini?
[mail function] ; For Win32 only. SMTP = 192.168.1.10 smtp_port = 25 ; For Win32 only. sendmail_from = [email protected] ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). sendmail_path = /usr/sbin/sendmail
0

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).

1 Comment

The machines are all in an internal LAN (no gateways even)
0

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.