Question

How can I change Return-Path: www-data@localhost.localdomain?

I have a huge issue with emails being blacklisted, due to the fact that their return-path is set to www-data@localhost.localdomain, so is there anyone who knows how to change that email to use my domain name?

This is one of the errors that I can see in my email headers:

*Received-Spf: neutral (google.com: 1.1.1.1 is neither permitted nor denied by best guess record for domain of www-data@localhost.localdomain) client-ip=1.1.1.1; *

Everything is setup correctly in my PHP function for sending an email, where the sender and reply emails are using the correct domain name, but not the return-path email?

$output .= ‘From: ‘.$this->headers[‘from’].’ <’.$this->headers[‘sender’].‘>’.“\r\n”; $output .= ‘Reply-To: ‘.$this->headers[‘from’].’ <’.$this->headers[‘sender’].‘>’.“\r\n”; $output .= ‘Return-Path: ‘.$this->headers[‘from’].’ <’.$this->headers[‘sender’].‘>’.“\r\n”;

I use an Ubuntu 16.04 installation with WordPress and I’ve activated the Postfix package, which is used to send email via a contact form and a simple PHP mail() function.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

It looks like my PTR is correct:

1.1.1.1.in-addr.arpa domain name pointer mydomain.com.

I’ve added two SPF records:

TXT	
mydomain.com
v=DMARC1; p=none	
3600
TXT	
mydomain.com
v=spf1 +a +ip4:1.1.1.1 ~all
3600

My /etc/hosts file contains the following:

127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost.localdomain localhost mydomain

My /etc/postfix/main.cf file contains the following:

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = mydomain.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = $myhostname, mydomain.com, localhost, localhost.localdomain, localhost
relayhost = 
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
inet_protocols = all

I’m sadly not a server administrator and some technical terms is totally alien for me, so I would appreciate a clear and simple explanation.

So what is incorrect here, or what else need to be changed?

Just to clear things out, I do not want to host any emails at DigitalOcean, I have an external resource for that, so I don’t want any MX records set up for emails.

I only want my visitors to contact me via my website and a form that uses PHP with a simple mail() function, which clearly submit content and sends an email.

The issue I have is that those emails ends up in the spam folder, because of the Return-Path: www-data@localhost.localdomain.

It seems to be very unclear on how to set this up properly, especially if I would like to use an normal email as the Return-Path: inquiry@company.com, which then would be the same as the sender email?

@richardpersson

How was Postfix setup?

PHP relies heavily on how you’ve configured sendmail. You can set From, Reply-To, and Return-Path, but unless your mail server is properly configured, it’ll still show as being sent by whatever user you are logged in as.

For example, on a Droplet I have deployed right now, the only configuration I’ve setup for sendmail is what was provided when I ran sudo apt-get -y install postfix, nothing more. As a result, when mail is sent using mail(), I see that the message was actually sent by

root@dev.localdomain

The reason dev.localdomain shows is because a hostname has yet to be set for the Droplet, which you need to do. This can be done by using the hostname command and then adding whatever you wish to use as a hostname as an option.

For example, running:

hostname dev.mydomain.com

Sets my hostname and changes the sent by header I see when viewing the mail to:

root@dev.mydomain.com

That being said, when it comes to running a mail server, there’s actually a lot more involvement than just installing and configuring Postfix to send mail. If you want e-mail to stay out of the SPAM box, you need to be setup to use SPF, DKIM, and potentially even DMARC (which can be setup with Postfix, but it’s a bit time consuming to do so).

You also need to have proper reverse DNS setup. That can only be setup by setting the name of your Droplet to the hostname you set using the command above.

When you created the Droplet, you remember the input box at the end? That’s where you can set the name of your droplet to match that of your hostname. You can optionally login to the DigitalOcean CP, click on the name of the droplet you want to modify, and then click on the droplet name and you’ll see an inline-edit input pop up. You can use that to change your droplets’ name after deployment.

Why does the name matter? DigitalOcean automatically creates your reverse DNS (i.e. PTR) records for you when you deploy a droplet. If the droplet name and the hostname of your droplet do not match, it won’t be considered valid when a lookup is performed.

All that being said, if you’re using WordPress and don’t want to go through the hassle of all the above, the best thing to do would be to use an external e-mail service such as Mailgun or SendGrid, both of which offer plugins to integrate with their services.

Using an external mail service removes the need for you to rely on properly setting up and configuring a working mail server on your end.