Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Possible Duplicate:
How to configure php.ini with remote SMTP?

We have a php application running on Linux which sends emails to there users. Currently its setup like php.ini is configured to send via local sendmail server but we have separate mail server for our organization for this domain. I want to send the php application emails via that remote smtp server so these emails can have the correct SPF records and sign via DKIM.

But I could not see such option in php.ini to specify the remote host address to forward emails to that, its for windows only.

I saw some post which suggest phpMailer but I could not find how to configure that so all our php application could send via our remote SMTP.

share|improve this question

marked as duplicate by HopelessN00b, mulaz, Michael Hampton, Scott Pack, Magellan Oct 8 '12 at 3:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers 2

up vote 1 down vote accepted

I would install nullmailer and configure it to forward emails to your relay server. The linux distribution that you are using most likely has nullmailer packages, so that a sendmail binary (that is command line compatible) is installed in the proper place.

If you do not want to install nullmailer, it is possible to do with sendmail too. If you want, I will update the answer.

UPDATE:

If you want to do this under sendmail, you have a number of choices:

(1) In sendmail.mc define the SMART_HOST to be your mail relay server:

define(SMART_HOST, `smtp:[relay.server]')dnl

(2) You can use FEATURE(nullclient).

(3) Modify rule set 0 to do this. In sendmail.mc add the following lines:

LOCAL_RULE_0
R$* < @ $* . > $*       $#esmtp $@ [relay.server] $: $1 < @ $2 . > $3

Do not copy-paste the code snippet above since the left hand side is separated from the right hand side with tabs and not spaces.

After you are done editing sendmail.mc you need to compile sendmail.cf and restart sendmail. In Debian this is done by running sendmailconfig. In CentOS this is done by running /etc/mail/make followed by service sendmail restart.

share|improve this answer
    
Thanks for the answer, it will be better if you could put the sendmail configuration as well. I have sendmail already installed so I will just configure to forward to the relay host. –  Toqeer Oct 1 '12 at 4:06
    
Answer updated. –  adamo Oct 1 '12 at 8:14

Please search first, this was asked before (e.g. in How to configure php.ini with remote SMTP?).

The PHP mail() function always uses sendmail (on Linux/Unix). There is no way to change that by php.ini. That leaves two other means:

  • For a single application you can replace all calls to the mail() function with calls to an alternative library (e.g. PHPMailer).
  • As a more general solution you can configure your local sendmail (or whatever program provides the sendmail command) to do the right thing, i.e. set the domain's mail server as a smarthost.
share|improve this answer
    
Another nice point, under Ubuntu I prefer to remove Postfix and install mailx and configure it in 'smarthost' mode that forwards mail to the network's mail server. Very little fiddling at install time when configured with 'dpkg-reconfigure'. –  Magellan Sep 30 '12 at 21:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.