Do i need to open 25 port to send emails with the php mail function?

21,163

Solution 1

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

Solution 2

No.

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.

Solution 3

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.

Solution 4

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:
21,163

Related videos on Youtube

Ben
Author by

Ben

Updated on September 17, 2022

Comments

  • Ben
    Ben over 1 year

    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.

  • hobodave
    hobodave about 13 years
    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.