Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Linux web app.

Do I need to open port 25 to only send emails using the PHP mail function? If I have to open port 25, how can I disable receiving emails?

Edit: I am asking because I understand that sendmail is the message transfer agent on my server.

share|improve this question
up vote 2 down vote accepted

php mail() function relies on sendmail like binary to send mail.

any MTA ( service listening on port 25 ) has program like sendmail that will serve the purpose.

if you don't want to have port 25 open, you can firewall it for all connections comming from the world; for example

iptables -I INPUT -p tcp -i eth0 --dport 25 -j REJECT

share|improve this answer


As long as your firewall rules permit outbound traffic you do not need to open port 25 to send an email.

Port 25 only needs to be open if you wish your machine to receive email.

share|improve this answer

It depends on how the firewall is configured on the server / gateway / wherever.

Most of the time, firewalls block incoming traffic, such as traffic on port 25 coming to your server. Having said that, I usually configure firewalls to only allow outbound traffic on port 25 from known mail servers.

Either way, it's really dependent on your firewall configuration, but to answer your question with as much detail as you asked it... opening 25 outbound does not equal having 25 open inbound. If you enable outbound traffic on port 25, you'll be able to send mail. If you leave it closed inbound, then you'll not be able to receive mail.

This of course depends where the firewall lives in your network topology...

share|improve this answer
Huh? No. Sending mail to a remote SMTP server uses a random source port. You do not need to "enable outbound traffic on port 25". You would "enable outbound traffic to port 25". If that's what you meant, apologies, but it's not clear. Also, outbound firewall rules are an advanced topic that I suggest inexperienced admins avoid. – hobodave Feb 17 '11 at 1:09
Yeah, apologies for not being clearer on that. I more meant that he'd need to enable outbound connections on 25 as a destination port. – dotalchemy Feb 17 '11 at 1:22

If you only want to send emails and not receive Emails you could open port 25 out but not in. Or you could use a non-standard port relay such as NO-IP relay( no relation to company). Though I am not sure why you want this.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.