Avatar of elepil
elepil
 asked on

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.
Apache Web ServerPHPEmail Servers

Avatar of undefined
Last Comment
Ray Paseur

8/22/2022 - Mon
Ray Paseur

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.
elepil

ASKER
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.
SOLUTION
sunnysunny

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
elepil

ASKER
To sunnysunny. No, it did not work, but thanks.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
elepil

ASKER
Thanks for the help!
Ray Paseur

Thanks for the points and thanks for using E-E! ~Ray