How do I configure Postfix and Nginx with multiple domains/hostnames?

June 10, 2015 997 views
PHP Email Nginx Ubuntu

Okey so as the title suggests, I am trying to configure Postfix to work with multiple domains.

When I use the PHP mail() function on my website I want postfix to use the hostname of the current Virtual host (server { } ).

For an example:

I have 2 domains, example.org and example.net

Postfix variable "myhostname" is set to example.net because the hostname can't be both example.org and example.net.

On example.org I am trying to use the PHP mail() function to send an email to my CRM. The CRM has only whitelisted the hostname example.net so it disallows the email from being received.

So I thought this might be possible in Nginx, to change the "myhostname"-variable depending on which Virtual host PHP is sending emails on.

If this is not possible I would love to hear other suggestions to get my example above to work, this problem is driving me insane.

With love,
Martin

Be the first one to answer this question.