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.
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.
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
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...
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.