Question

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

Posted June 25, 2020 228 views
NginxPHPDigitalOceanDebian 10

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

1 comment
  • I figured it out, I had to update my /etc/mailname file, I’m not sure why it worked before, but now I can send mails using my domain name

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.

×
2 answers

Just had to update my /etc/mailname file

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

  • The name of the droplet seems fine, and nowhere in /etc/hostname nor /etc/hosts are showing anything about my old droplet name, I’m actually trying to change my fqdn, but it doesn’t seems to have any effect on my domain name, I’ve also checked my PTR records, and did a Reverse DNS check and everything seems to be ok, so I don’t know what to do now

  • Ok, when I do this:
    $headers .= ‘From: Something Something@mydomain.com’ . “\r\n”;

    I get the mail from Something@myolddropletname

    But when I do this:
    $headers .= 'From: Something <Something>’ . “\r\n”;
    I get the mail from Something@myhostname.mydomainname.com

    But I want it to be only my something@mydomainname.com

    • Hello, @Dantael

      What you can do is to simply save the from mail address in another variable and then use it the execution:

      $from = "something@mydomainname.com";

      Hope that this helps!

      Regards,
      Alex

Submit an Answer