I'd like to send mails using a PHP script that has been deployed on a CentOS machine. Problem is there is no mail server configured. There is, however, another linux machine that has a mail server configured. How can I use the "good" machine to send an email?

P.S. I have the credentials of the "good" mail server.

  • Why not configure your machines email server? Also, are you sure there is no email server configured. Linux distributions generally configure email at least locally for system purposes - so services can send messages to the superuser/owner of the system etc. Apr 5, 2011 at 10:43
  • See also: unix.stackexchange.com/questions/7044/…
    – alex
    Apr 5, 2011 at 11:28

3 Answers 3


Configure postfix on the php host to act as a relay to the "good" server.

in /etc/postfix/main.cf (on the php host)

relayhost = goodmailserver.com

and do a "postfix reload"

Also ensure goodmailserver.com is configured to accept mail from your php host


I am not sure how detailed an answer you expect, but just make an SMTP connection to the machine running the email server at port 25 or whatever port it is listening on, and send an email to it to be relayed. I don't use PHP, but I expect there is some library that will do it for you. However, using your machine's email server is better.

I think this is basically the same as this question - Send email using GMail SMTP server from PHP page.


Edit your php.ini file to set the SMTP server settings. The default settings go to localhost.


Err... apparently that setting is Windows only according to that document. I honestly can not wrap my head around PHP's design.

  • lol..i tried that too and then just as I saved the document, I saw the "Windows only" comment. Apr 6, 2011 at 7:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .