[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 336
  • Last Modified:

How Do I Send Emails With PHP Showing From "Name" <user@domain.com> Instead of webHostUser@webHostDomain.com?

Am writing a PHP script to email a confirmation link in order to double-opt-in emails.

When I send the email, instead of showing the email as coming from:
"Joe Smith" <me@domain.com>
...it shows the email as coming from:
hostingusername@server.hostingcompany.com (hostingusername@server.hostingcompany.com)

For this application, HostMonster is the hosting company. So I read their support page:

...which says you are required to put a properly formatted , valid From: field in the email's header, or else it will change the From: address to username@host###.HostMonster.com. (Which is what is happening, it seems.)

This page gives the following examples of properly formatted From fields:
From: user@domain.com
From: "user" <user@domain.com>

Problem is, I don't see how I am not conforming to this standard. Here is my php code for defining the header (email addresses and names have been changed for anonymity, but the format is exactly as follows):

$header = 'Reply-To: "Joe Smith" <joesmith@domain.com>\n';
$header .= 'Return-Path: "Joe Smith" <joesmith@domain.com>\n';
$header .= 'From: "Joe Smith" <joesmith@domain.com>\n';
$header .= "Organization: Joe Smith Corp\n";
$header .= "Content-Type: text/plain\n";

HostMonster tech support referred me to the document I already had found and applied above. They said they do not troubleshoot code, and suggested online help forums.

How can I fix this?
  • 3
  • 2
1 Solution
Try changing From:
$header .= 'From: "Joe Smith" <joesmith@domain.com>\n';


$header .= 'From: 'joesmith@domain.com' . "\r\n"
FirstDirectAuthor Commented:
@becraig Tried this just now exactly as you suggested, but it still doesn't work. Thanks for suggesting, though.
I forgot to indicate the reply to:

$to      = 'user@domain.com';
$subject = 'Subject';
$message = 'This is a test';
$headers = 'From: webmaster@yourdot.com' . "\r\n" .
   'Reply-To: webmaster@yourdot.com' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);

Open in new window

FirstDirectAuthor Commented:
@becraig That did the trick! Many thanks!
FirstDirectAuthor Commented:

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now