mail() without sendmail on linux – a hack

Some time ago, my friend Amy Hoy was working an environment where a higher power disallowed them from installing a mail server on their machine – yet they were using 3rd party software that required the mail() function be available – unless much hacking was to be done.

So, I came up with a solution, thanks to Sara Golemon this will work nicely.

First, PHP should not compile with a mail() function if sendmail is not detected, however if you have a sendmail (or compatible) binary on your system, as most *nix’s do, this will invariably fail. The first step is to disable it during compile, otherwise we cannot override it:

  1. Run ./configure as normal
  2. Edit main/php_config.h
  3. find the line that reads ‘#define HAVE_SENDMAIL 1‘ and comment it out using /* and */
  4. save and exit
  5. continue compilation as normal (i.e. make && make install)

Next, we need to define our own mail() function that uses an external mail server, I would suggest using the PEAR::Mail package or some such, but I’m leaving this as a user excercise because its 7:13am – save this in a file accessible from all hosts

Finally, use the php.ini setting auto_prepend_file to include this file in all PHP scripts, and they will transparently be able to use you mail() function :-)

Hope this helps someone.

- Davey

Comments are closed.

Twitter

@dshafik Anytime tools are released that give just anyone the ability to do something without coding, programmers see a pay cut in contracts

@fasterkitty [3 hours ago]

@fasterkitty I think that depends on the quality of the apps the Flash folks put out...

@dshafik [3 hours ago]

@fasterkitty from what I hear, they are already culling apps that violate the Desktop/Widget rule. For example: http://bit.ly/cb3l0B

@dshafik [3 hours ago]

Looking for a design, thinking of using 99designs; unless someone I know wants to do some work for me? (for pay!)

@dshafik [3 hours ago]

@dshafik can you please call our support, so that we could help you with those issues?

@EyeFiCard [7 hours ago]

Books & Things