13

I tried to sending out an email using php mail() function but it failed somehow, complaining that a real domain name is required. The following is observed in the maillog:

sendmail 4984 r25984: from=apache, size=273, class=0, nrcpts=1, msgid=<201.r25@localhost.localdomain>, relay=apache@localhost
sendmail 4985 r25985: ruleset=check_mail, arg1=, relay=mydomain.com [127.0.0.1], reject=553 5.5.4 ... Real domain name required for sender address
sendmail 4984 r25984: to=external@server.com, ctladdr=apache (48/48), delay=00:00:01, xdelay=00:00:00, mailer=relay, pri=30273, relay=[127.0.0.1] [127.0.0.1], dsn=5.6.0, stat=Data format error
sendmail 4984 r25984: r25984: DSN: Data format error

cron is able to send email to external@server.com whenever there is a problem with logrotate. I am not sure why php is unable to do so. I tried making changes to the default configuration in `sendmail.mc with the following:

MASQUERADE_AS(`mydomain.com')dnl
FEATURE(masquerade_envelope)dnl
FEATURE(masquerade_entire_domain)dnl
MASQUERADE_DOMAIN(localhost)dnl
MASQUERADE_DOMAIN(localhost.localdomain)dnl
MASQUERADE_DOMAIN(mycom)dnl

But, it doesn't seem to have any effect. The header from address in php mail function has already been set. I have also ensured that SELinux httpd_can_sendmail is enabled. What else to I need to do to get the mail delivered?

4 Answers4

10

I think I have just solved it. I have the following in /etc/hosts:

127.0.0.1 www.mydomain.com test.mydomain.com
127.0.0.1 cdn.mycdn.com
127.0.0.1 localhost.localdomain localhost myserver.com

What I need is to place myserver.com in front of the line with localhost.localdomain so that sendmail will think that it is using a real domain to send out the email.

gpojd
  • 132
3

In my case, on Ubuntu 16.04 on an AWS instance, what was needed was to add to /etc/mail/sendmail.mc:

define(`confDOMAIN_NAME', `mydomainname.com')dnl

on a line before the MAILER_DEFINITIONS line toward the end of the file, AND add the same line to the end of /etc/mail/submit.mc. Then type sudo su for root permissions, and compile to config with:

m4 sendmail.mc > sendmail.cf
m4 submit.mc > submit.cf

...then exit sudo. Finally, sudo service sendmail restart to restart sendmail, and from thereon emails were appearing as sent from the domain name. None of the other FEATURE or MASQUERADE commands were required, nor an entry in the /etc/hosts file.

Theo d'Or
  • 131
1

You have to configure, in your scripts, the headers of your email to have From: sender@domain.com.

fboaventura
  • 1,163
1

In your sendmail.mc add:

LOCAL_CONFIG
Djmyserver.com

Recompile sendmail.cf, restart sendmail and you should be OK

adamo
  • 7,045