Split site up, now subdomains cant mail()

I’m hoping this one is obvious to someone :slight_smile:

For reasons unrelated to the thread we found a need to segregate certain parts of our web services across multiple machines.

I used to have 1 Virtualmin install hosting website / email / Moodle / blog, the whole domain pointed here to the top level.

Now I have 3 machines , the top level “mydomain.com” is on server 1, server 2 has “mail.mydomain.com” (The mail server, with fresh mx records etc) and server 3 has “work.mydomain.com” with the blog and Moodle.

DNS is @ godaddy, and inbound / outbound mailing from the mailserver works like a charm.

All 3 servers run Virtualmin, and were made by taking a single backup, and restoring it to the two other machines with fresh Virtualmin installs. I then purged the various components held elsewhere so each system only contained the parts it was to distribute. All 3 servers share a LAN and a common firewall.

So the transfer went great with one single catch, in php there is a function called mail() that is used to send email messages. That command doesn’t produce any results on server 1, and 3 now. It continues to work fine on server 2, the mail server.

In the error logs, the outbound server throws a message containing
" to=c.babb-mydomain.com@work.mydomain.com, orig_to=c.babb@mydomain.com, relay=local, delay=0.78, delays=0.57/0.01/0/0.2, dsn=5.1.1, status=bounced (unknown user: “c.babb@mydomain.com

I think it is saying that the server is trying to handle the message, rather than forwarding it to the remote server @ mail.mydomain.com

Any idea how I can tell it to route to the new mail server for delivery?
And assuming I get that far, how do I tell the receiving server to allow it?

A tutorial would be fine, but I’d sure love to know where I have flubbed :wink: Im sure its my fault somehow!

Not really your fault, just missing a couple tiny steps. I’m guessing Postfix sees the domain name on your system and thinks that makes it the right destination for the mail.

You can solve that in a few ways…first make sure no MX/A records exist locally that point to the server itself in relation to mail. Then, you can decide whether you want to change your PHP apps to connect directly to the mail server instead of trying to send using the local sendmail program (probably preferable, as setting up Postfix to explicitly relay through another server can be tricky and may introduce security concerns if you host websites for untrusted users).

You’d need to give the PHP apps a mail username and password so they can authenticate (the default configuration after install on a Virtualmin system is that local users can send mail without authenticating, but any remote user needs to authenticate, this makes it easy for web apps to send mail, but again has security considerations). But, most PHP apps will allow you to configure them to relay through an SMTP authenticated host…so do that, and point them at your mail server.

There is an MX Record, but for itself. I think ill leave that. I am looking at php mailer. As all of the applications on the system are written by me I can implement that. Thank you!