Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use default PHP mail function with SMTP server on Linux

I am working on a php/c# project which is an Email Server with a web interface to manage the Email Server application.

The program is supposed to work on windows and linux but I have been mostly doing my development in windows.

I've not come onto testing in Linux and have found a horrible problem.

From what I have googled on Windows PHP you can choose an SMTP server that you want to use, but it looks as if on Linux you don't have this option so when PHP sends an email it completely bypasses my program.

Is there a way to make PHP use an SMTP server of your choice, I know you can use PEAR to overrride the SMTP settings but I'd prefer that the standard PHP mail function would work so other software like PHPBB forum would send emails via my SMTP server instead of the default php mail.

Is this something that is possible or is my only option to use pear?

like image 463
Boardy Avatar asked Aug 13 '12 21:08

Boardy


People also ask

What is the default SMTP port value set for PHP mail?

Used under Windows only: host name or IP address of the SMTP server PHP should use for mail sent with the mail() function. Used under Windows only: Number of the port to connect to the server specified with the SMTP setting when sending mail with mail(); defaults to 25.

Does PHP mail function requires a running mail server?

IIRC the PHP mail function on Linux typically defaults to using the sendmail command. Sendmail (or any local replacement SMTP server) needs not be explicitly configured nor be running as a daemon to work.


1 Answers

You standard php mail function will just send to whatever is defined as the sendmail _path in php.ini

This is typically sendmail -t -i

You would need to configure sendmail to use smtp.

FWIW, most developer who do a lot of mail sending from PHP apps revile the mail() and instead use one of many mailing libraries (or services) which provide better configurability/reliability.

You could for example pipe the mail function to your own PHP script and use whatever library you wanted to in that script in order to do mail sending (and thus preserving the use of mail() function across applications).

like image 59
Mike Brant Avatar answered Sep 20 '22 13:09

Mike Brant