Search code examples
phpphpmailer

PHPMailer Mail Server Name Showing in From Line in Emails Sent


I have a website using PHP 8.1.2. I'm using PHPMailer to send emails. The site is hosted on a Shared Web Hosting server. Everything is working with no errors. But, in the emails that are sent, the name of the mail-server is showing in the From line. I.e: Living Muay Thai via server501.stormwire.com

I see the same thing when using php's mail() method. My guess is this is some sort of default behavior either in PHP or in the mail server. Is there a way of preventing the mail-serer name from showing when sending emails in PHP?

My Code:

//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader
require '../vendor/autoload.php';

//Create an instance; passing `true` enables exceptions
$mail = new PHPMailer(true);

//From email address and name 
$mail->From = "[email protected]"; 
$mail->FromName = "Living Muay Thai";
...
...
$mail->send();

//output in email sent
>> Living Muay Thai via server501.stormwire.com

Solution

  • @Synchro was right. I use a shared webhosting service: Stormwire.com. In the Cpanel >> Domans, select the domain and then Manage.

    Stormwire has the code I needed to add to remove the via server501.stormwire.com from the From line in mail() emails.

    The dns for my domain name is not on stormwire and is owned/controlled by another. I reached out to that person with the instructions to update the dns. It is all good now.