HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (
-   Installation/Configuration (
-   -   php mail() sent as (

bwragg 26th February 2007 13:52

php mail() sent as
if I do the following in a php page


if (mail($ADDR,"Testing","This is a test"))
the mail gets sent from I assume this is happneing becuase the httpd server is running as the apache user? Is there any way to stop this so that the email is sent automatically from the domain the page is being run in?

I know you can add the $header parameter to the mail function with a "From:" statement in it, but is there anyother way.



Ben 26th February 2007 14:10

You can change the sendmail_path of php.ini
so that you add
to php.ini in general or you set this value via php_admin_value in the httpd.conf per vhost.

bwragg 26th February 2007 23:17

So for each domain do I need to add this to the apache directives:

php_admin_value sendmail_path '/usr/sbin/sendmail -t -i'

Does that look correct?

I tried the sendmail_from parameter, but that didn't do a thing. Don't know why?



edge 27th February 2007 00:07

If you add a "from" email address in the PHP mail() , it will use that instead of the
You will need to add it in the "headers"


$to = "";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "";
$headers = "From: $from";
echo "Mail Sent.";

bwragg 27th February 2007 01:07

That works great, Thanks.

Is the reason its being sent by apache due to the fact that apache is the user that is running php?

If I setup my system differently so that php was running using something like suphp would the email go out via the owner of the file rather than the apache user?



Ben 27th February 2007 09:33

If you set the Header From, just remember that this is only the X-Header, i mean it is never the less displayed in the email riht, but in the header you can see the "original" E-mailadress anyway, just fyi.

Emile van EWeden 13th February 2013 08:49

I there.
I have the same issue when sending email using php. I also tried the example by the user "edge" with no luck. What else can I try? Thank you


Feb 13 06:55:30 mailer postfix/qmgr[1273]: 4BB1E1D3A4: from=<apache@serv2.wugnet>, size=473, nrcpt=1 (queue active)
Feb 13 06:55:33 mailer postfix/smtp[2507]: 4BB1E1D3A4: to=<>,[]:25, delay=3.8, delays=0.86/0.03/1.8/1.1, dsn=2.0.0, status=sent (250 OK id=1U5Vyp-0006Ba-G0)

edge 13th February 2013 09:46

You can try by adding the -f option to it.

Somtehing like this: mail($to,$subject,$message,$headers,"-f".$from);

Emile van EWeden 13th February 2013 10:28

Hi still doing the same :confused:

Emile van EWeden 18th February 2013 16:10

Hi i got it working by editing ssmtp.conf.

All times are GMT +2. The time now is 03:51.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.