Link to home
Start Free TrialLog in
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.
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

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.
Avatar of elepil
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
Avatar of sunnysunny
sunnysunny

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of elepil

ASKER

To sunnysunny. No, it did not work, but thanks.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of elepil

ASKER

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