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:

<?php
$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:

force_sender=no-reply@localhost.com

Open in new window


I can't see anything else I can modify that might affect the FROM field. Anyone have any advice? Thanks.
elepilAsked:
Who is Participating?
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.
0
elepilAuthor Commented:
I'm actually using Google's gmail server. Here's the info I put in the sendmail.ini:

smtp_server=smtp.gmail.com
smtp_port=587
auth_username=your_email_address@gmail.com
auth_password=your_email_password
force_sender=your_email_address@gmail.com

Open in new window


I have no local mail server.
0
sunnysunnyCommented:
$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
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

elepilAuthor Commented:
To sunnysunny. No, it did not work, but thanks.
0
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.
http://php.net/manual/en/function.mail.php

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
 */
error_reporting(E_ALL);


// SET UP THE PARAMETERS FOR OUR CALL TO THE MAIL() FUNCTION
$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";

// CALL THE MAIL() FUNCTION
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 10.202.4.13 with SMTP id 13csp240262oie;
        Sat, 11 Apr 2015 02:03:28 -0700 (PDT)
X-Received: by 10.107.169.74 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. [69.65.9.221])
        by mx.google.com with ESMTP id dx6si1878191igb.51.2015.04.11.02.03.27
        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=69.65.9.221;
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

0

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!
0
Ray PaseurCommented:
Thanks for the points and thanks for using E-E! ~Ray
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.