Pergunta

I recently setup a CentOS server that I am planning on using just for email. I installed and configured Postfix and sending / receiving messages via command-line is working fine.

I want to be able to send mail to my end-users from a PHP application that is hosted on a separate CentOS server, using the dedicated mail server's Postfix as the MTA. Is this possible? Or do I need to install Postfix on the server where Apache / PHP resides?

If it is possible, how do I go about connecting / relaying the messages that are to be sent?

I am looking for the common conventions / best practices for running my own mail server, so any advice is much appreciated. Thanks!

Foi útil?

Solução

If you use mail() in PHP, the documentation states that it only uses sendmail on the local machine.

You may, however, setup sendmail to forward mail to your other server, like in this link : http://www.cyberciti.biz/faq/configure-sendmail-as-a-smart-host/

According to that page, you can do this:

Add to /etc/mail/sendmail.mc:

define(`SMART_HOST',`my_smtp_server')

Then restart sendmail. If it still doesn't work, you might need to run:

m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

or

cd /etc/mail; make

and then restart sendmail.

If you need to fake the server name which sendmail uses, you might add this in sendmail.nc (ref.: https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s2-email-mta-sendmail.html):

FEATURE(always_add_domain)
FEATURE(`masquerade_entire_domain')
FEATURE(`masquerade_envelope')
FEATURE(`allmasquerade')
MASQUERADE_AS(`my_public_domain.')
MASQUERADE_DOMAIN(`my_public_domain.')
MASQUERADE_AS(my_public_domain)

Outras dicas

You can configure postfix as MTA on the same server on which php/apache resides if you keep it remote you have to ensure proper connectivity to MTA and due to any timeout issue your mails might not get delivered. So you can run postfix on the local apache/php server and configure it's settings with php to send email.

http://email.about.com/od/emailprogrammingtips/qt/How_to_Send_Email_from_a_PHP_Script.htm

The above link would be helpful.

Thanks & Regards,
Alok Thaker

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top