Apache/PHP sendmail FROM issue

I've gotten my local Apache server and PHP to work with sendmail. But there is one problem. First, here is my PHP script:

$to = "myEmail@gmail.com"; // ***** LET'S SAY THIS IS MY EMAIL ADDRESS
$subject = "Testing from local PHP at " . strftime("%T", time());

$message = "Hello, PHP world!";

$from = "no-reply@localhost"; // ***** THIS IS THE 'FROM' EMAIL ADDRESS I SPECIFIED
$headers = "From: {$from}";

 * The mail() function returns true or false depending on whether it was successful
 * in sending it.
$result = mail($to, $subject, $message, $headers);
echo $result ? "Sent" : "Error";

Open in new window

The email succeeds, but the FROM always has myEmail@gmail.com, not the no-reply@localhost I specified. Can anyone tell me how to correct this? There aren't really much to configure in sendmail.ini, and I even did:


Open in new window

I can't see anything else I can modify that might affect the FROM field. Anyone have any advice? Thanks.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Is this on a hosted server?  If so, your service provider might be changing your email headers.  Not sure about this -- email is amazingly simple in concept but amazingly complex in implementation.

I'll see if I have an example that designates the "From" and if I can find one, I'll post it here.
elepilAuthor Commented:
I'm actually using Google's gmail server. Here's the info I put in the sendmail.ini:


Open in new window

I have no local mail server.
$result = mail($to, $subject, $message, "no-reply@localhost");

Open in new window

I know the above may not make sense but sometimes a hard-coded string does the magic. Try it will just take a minute
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

elepilAuthor Commented:
To sunnysunny. No, it did not work, but thanks.
Ray PaseurCommented:
Please see the documentation here about the fourth mail() parameter.  It's not simply a "From" address -- it's a collection of additional mail headers, and the collection needs to obey the required formats from the RFC.

Here is a script I used that worked successfully.  Note the double quotes and the format of the line endings in the headers.
<?php // demo/temp_elepil.php

 * Send Mail from a PHP Script
 * See: http://www.experts-exchange.com/Software/Server_Software/Web_Servers/Apache/Q_28653982.html

$to      = 'Ray.Paseur@Gmail.com';
$subject = "Test Message";
$text    = "Howdy from AnglerStats.com,\n\n";
$text    .= "Let's see if this goes through!";
$headers = "From: AnglerStats.com <Jack@AnglerStats.com>\r\n";
$headers .= "Reply-To: Ray.Paseur@GMail.com\r\n";

mail ($to, $subject, $text, $headers);
echo "Mail sent";

Open in new window

Here is the complete email, including all headers:
Delivered-To: ray.paseur@gmail.com
Received: by with SMTP id 13csp240262oie;
        Sat, 11 Apr 2015 02:03:28 -0700 (PDT)
X-Received: by with SMTP id s71mr8310305ioe.46.1428743007913;
        Sat, 11 Apr 2015 02:03:27 -0700 (PDT)
Return-Path: <iconoun@server144.securednshost.com>
Received: from server144.securednshost.com (server144.securednshost.com. [])
        by mx.google.com with ESMTP id dx6si1878191igb.51.2015.
        for <Ray.Paseur@gmail.com>;
        Sat, 11 Apr 2015 02:03:27 -0700 (PDT)
Received-SPF: none (google.com: iconoun@server144.securednshost.com does not designate permitted sender hosts) client-ip=;
Authentication-Results: mx.google.com;
       spf=none (google.com: iconoun@server144.securednshost.com does not designate permitted sender hosts) smtp.mail=iconoun@server144.securednshost.com
Received: by server144.securednshost.com (Postfix, from userid 503)
	id 6CE5D3301496; Sat, 11 Apr 2015 04:03:27 -0500 (CDT)
To: Ray.Paseur@Gmail.com
Subject: Test Message
From: AnglerStats.com <Jack@AnglerStats.com>
Reply-To: Ray.Paseur@GMail.com
Message-Id: <20150411090327.6CE5D3301496@server144.securednshost.com>
Date: Sat, 11 Apr 2015 04:03:27 -0500 (CDT)

Howdy from AnglerStats.com,

Let's see if this goes through!

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
elepilAuthor Commented:
Thanks for the help!
Ray PaseurCommented:
Thanks for the points and thanks for using E-E! ~Ray
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.