How do I fix my DigitalOcean LAMP server to send php email from multiple domains?

June 3, 2018 88 views
Email LAMP Stack PHP Ubuntu 16.04

In PHP, I'm using mail($to, $subject, $content, $headers, '-f user1@domain2.com') and I successfully receive the email at yahoo_user@yahoo.com. However, the "from" return address (in Yahoo! Mail) shows as "user1@domain1.com" instead "user1@domain2.com". My /var/logs/mail.log looks like:

Jun  2 18:30:39 domain1 sendmail[2872]: w531Udbv002872: from=
user1@domain2.com, size=6059, class=0, nrcpts=1, msgid=<20180
6030130.w531Udbv002872@domain1.com>, relay=www-data@localhost
Jun  2 18:30:39 domain1 sm-mta[2873]: w531UdPW002873: from=<u
ser1@domain1.com>, size=6279, class=0, nrcpts=1, msgid=<20180
6030130.w531Udbv002872@domain1.com>, proto=ESMTP, daemon=MTA-
v4, relay=localhost [127.0.0.1]
Jun  2 18:30:39 domain1 sendmail[2872]: w531Udbv002872: to=ya
hoo_user@yahoo.com, delay=00:00:00, xdelay=00:00:00, mailer=r
elay, pri=36059, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, st
at=Sent (w531UdPW002873 Message accepted for delivery)
Jun  2 18:30:40 domain1 sm-mta[2875]: STARTTLS=client, relay=
mta6.am0.yahoodns.net., version=TLSv1.2, verify=FAIL, cipher=
ECDHE-RSA-AES128-GCM-SHA256, bits=128/128
Jun  2 18:30:41 domain1 sm-mta[2875]: w531UdPW002873: to=<yah
oo_user@yahoo.com>, delay=00:00:02, xdelay=00:00:02, mailer=e
smtp, pri=126279, relay=mta6.am0.yahoodns.net. [98.136.101.11
7], dsn=2.0.0, stat=Sent (ok dirdel)

As you can see, I'm using sendmail (8.15.2) and I'm looking only to send mail out from multiple domains (domain1.com, domain2.com, domain3.com, etc). I've tried all kinds of sendmail files, features and commands: sendmail.mc, submit.mc, use_ct_file, use_cw_file, mailertable, virtusertable, genericstable, local-host-names, trusted-users, GENERICS_DOMAIN(), RELAY_DOMAIN(), sendmailconfig. SMART_HOST seemed to break everything.

The configuration always uses the line from /etc/hosts that looks like:

127.0.0.1 localhost domain1.com localhost.localdomain

I've tried messing around with MX and TXT (SPF) records but I don't know what I'm doing:

MX domain2.com 165.227.43.34 10 14400
TXT domain2.com v=spf1 ip4:165.227.43.34 a mx -all 3600

sm-mta seems to be converting user1@domain2.com to user1@domain1.com. Also, verify=FAIL looks suspicious.

Can you help me interpret what is going on here and what I can do to fix it? Can I fix sendmail to pass through the "from" address rather than always changing it to what is in /etc/hosts?

I don't need to receive email but I'm willing to set it up if it helps with verification. I'm also willing to switch from sendmail to exim4 or something else if that will help.

Be the first one to answer this question.