PHP Fatal error: Call to undefined function: mail()
Or: "How to fix this weird (and frustrating) error"
So, we got this weird (and frustrating) error on our production server and I didn't find much help on Google at the time. We got to fix it, so now is the time to give back.
Executive summary: This error occurs because PHP couldn't find sendmail at compile time. So the mail function didn't get built, thank you. Here's what to do to fix it:
If you compiled PHP before compiling (or installing) Sendmail, you just have to recompile PHP again (with Sendmail installed) and, hopefully, you're done.
If you use QMail (that was our case), you have to fool PHP that Sendmail is actually there, using QMail's wrapper. Just do: ln -s /var/qmail/bin/sendmail /usr/sbin/sendmail , recompile and, hopefully, you're done.
You're using some other esoteric mail server which is not Sendmail. If it has a wrapper to Sendmail, try the QMail tip (doing a symbolic link to the wrapper). If you don't have a wrapper, well... you're on your own. Unless you really need to use that mail server, I recommend QMail or Postfix.
In all cases you must recompile. It's important to do a make clean and then do the whole configure/make/make install dance, otherwise you'll compile the same configuration (with no mail function) all over again. Yes, I did that twice, silly me.
I don't know exactly in which places PHP looks for Sendmail, but I know one of them is /usr/sbin/ (to make it clear, it looks for the file /usr/sbin/sendmail).
Hope that helps.
Revisions:
2004/01/13 - Thanks to Oliver for pointing an incorrect ln call. It's fixed now.
Back to my page