Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Testing email functions within PHP on my local machine



Dave Gutteridge writes:

 > With cryptic tutorials on the net with phrases like "enable SMTP
 > AUTH for Postfix", as if that is supposed to be a self standing
 > instruction, this is beyond both my ability and the scope of my
 > endeavors. I'm just trying to get PHP to send an email, not become
 > an sendmail protocol administrator.

Gah.  SMTP is hard, true, but only because it really is simple.  So
simple that it is defenseless against the buccaneers on the Internet.

If you keep everything on the local box, though, it's perfectly safe,
and simple to use.  I don't know of any installations that prevent
local delivery, so you just set it up as the default and let the
firewall keep the pirates out.

I would advise staying away from Sendmail, just because it's
notoriously cryptic and hard to configure.  Use Exim or Postfix.
Yeah, I know you already installed Sendmail; it may well be worth
uninstalling it and using something with a more modern configuration
system.

You may configure it to start a server daemon.  Usually something like
/etc/init.d/postfix start will do that by hand, and you may prefer
that if you don't want it running by default since you don't need it.
You'll also need to shut it down by hand in that case.

Configure the firewall to block all connections from outside of your
box to port 25.  Make sure localhost can get through to it, of course.
In iptables, something like

iptables -A INPUT -p tcp -s 127.0.0.1 -d 127.0.0.1 --dport 25 -j ACCEPT
iptables -A INPUT -p tcp --dport 25 -j REJECT

should probably work.  Test that it works from that machine with
telnet localhost 25, and that is doesn't work from another machine
with telnet thatbox 25.  "Working" looks like this:

steve@example.com ~ $ telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 uwakimon.sk.tsukuba.ac.jp ESMTP Postfix
QUIT
221 2.0.0 Bye
Connection closed by foreign host.
steve@example.com ~ $ 

(you type the QUIT to shut down the connection cleanly).  "Not working"
looks like this:

chibi:MacPorts steve$ telnet localhost 25
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
chibi:MacPorts steve$ 

(You may not see two attempts, but only one; it depends on whether
your box and telnet are configured to do IPv6.)

Configure an alias (often in /etc/aliases,
but see your MTA's docs) as

test: dave

Where "test" is any name you will recognize as testing your PHP
script, and "dave" is the account name you are using on that box.  Run
the newaliases command (you'll probably need to su or sudo).

Then use "test", "test@example.com", or "test@example.com" as the test
address in your PHP script.  (Cut-and-try; any of those might fail
depending on the configuration of your mailer, but the simplest, just
"test", is quite likely to work.)

Also test those from your local MUA.



Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links