12

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
  • You edited the sendmail.mc, changed the lines localhost.localdomain and localhost to something meaningful and compiled the mc file into sendmail.cf? Mar 5, 2013 at 11:58
  • @fboaventura, no, I uncommented the two lines by removing dnl in front of them. Mar 5, 2013 at 12:35
  • Can you add the relevant part of your php script, where you are invoking mail()? And, the sendmail.mc isn't the proper configuration file, this file must be compiled into sendmail.cf using the m4. Mar 5, 2013 at 13:07
  • @fboaventura, thanks, I know that regarding the compilation requirement, I am able to get it work now. See my answer below. Thanks for your help :) Mar 5, 2013 at 13:12

4 Answers 4

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.

1
  • 3
    You could definately accept your own answer is that was the solution ... As a sidenote, it is usually /etc/hosts (with an "s"), other than that: good answer!
    – Levite
    Jun 26, 2015 at 9:41
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.

1
  • Instead of running these m4 commands by hand you can run make that does them for you (among other things).
    – bfontaine
    Aug 19, 2022 at 15:41
2

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

1
  • Sorry, I should have mentioned that this has already been set in headers. Mar 5, 2013 at 11:31
1

In your sendmail.mc add:

LOCAL_CONFIG
Djmyserver.com

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.