1

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.

Toqeer
  • 1,241
  • 3
  • 14
  • 20

2 Answers2

2

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.
mschuett
  • 3,146
  • 21
  • 21
  • 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
1

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.

adamo
  • 6,925
  • 3
  • 30
  • 58
  • 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 01 '12 at 04:06
  • Answer updated. – adamo Oct 01 '12 at 08:14