Question

Wrong domain when sending mails from PHP, how to fix it?

I had to rename my droplet to send mails, and it was renamed to my domain name, because I needed to be fqdn. When sending mails using php mail() function, it worked just fine, and the mails were received from something@mydomain.com, but then I turned off my droplet, resized it, turned it on again, and now my mails that are sent using php mail are being received from something@myolddropletname that is not even a domain, so I don’t know how to fix it.

My mails look something like this:

https://ibb.co/D94XJ5X

Show comments

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.

Accepted Answer

Just had to update my /etc/mailname file

alexdo
Site Moderator
Site Moderator badge
June 25, 2020

Hello, @Dantael

Would you mind checking that the hostname of the server is not changed back to what it was before your original change? I’m asking because you’ve mentioned that you’ve renamed the droplet in the past and now after the reboot this is no longer working for you.

In order to change the droplet’s name you can follow these steps:

  1. Login to the Digital Ocean Control Panel
  2. Click the droplet you want to rename
  3. Then, on the droplet detail window, click on the name of your droplet (you wouldn’t know you could)
  4. Change the name in the entry field and click the check mark

Make sure you also edit your droplet’s hostname internally as well. Update /etc/hostname and /etc/hosts and then reboot the droplet.

Hope that this helps!

Regards, Alex

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.