Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP ini question 1

Status
Not open for further replies.

btaber

Programmer
Joined
May 26, 2002
Messages
307
Location
US
I have a custom script handling the sendmail_path in the php.ini in order to set the Return-Path mail header correctly. Is it possible to use environment variables in the ini? something like:
sendmail_path = '/mymail.pl' SERVER_NAME
so I can pass the server name to my custom script?

Brian
 
As long as the environment is already present to the ini file, I dont see where it would be a problem. Is there an issue with hardcoding the server name?

___________________________________
--... ...--, Eric.
 
You can't use environment varible references in php.ini. That file is only read, not interpolated.

What MTA are you using?



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I had tried that but that is set by apache, so it isn't available in the ini. I use the perl script to extract the "From" address in the message, then I pass it along to sendmail with /usr/sbin/sendmail -t -i -f "address". If you don't speciify any headers with the mail command in PHP, it does not have a from address, so I wanted to make it apache@somedomain.com, somdomain.com being the site the php script was access from. Hope this makes sense.

Brian

 
Thank you sleipnir214, I wasn't sure of that. I use postfix, and due to spam, many mail servers will not accept messages with improper Return-Path headers, by default, it is "Return-Path: apache", which don't work....
 
PHP's mail() function has the capability of sending that "-t -i -f address" command-line parameter to sendmail.

See mail() in the PHP online manual, paying particular attention to the fifth parameter of that function.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
There should be a default address you can set in your ini file. If you set "sendmail_from" in there, you should have a default without having to set it.

___________________________________
--... ...--, Eric.
 
Yes, I am aware of that, but not everyone is (including our customers). That is how I would do it, but PHP makes some things too simple sometimes :)

(although I love it!)

 
err, let me clarify, you should have a default without having to set it in your script, provided its in your ini file.

___________________________________
--... ...--, Eric.
 
Sorry, this is the most active posting I have ever had. I am not even done typeing and my mail client is dinging! LOL

the:
"Yes, I am aware of that, but not everyone is (including our customers)."

is in response to:
"PHP's mail() function has the capability of sending that "-t -i -f address" command-line parameter to sendmail"

 
So basically, you are just doing it this way so the user doesnt have to code correctly, lol

___________________________________
--... ...--, Eric.
 
What I have now works well, it prevents bounce messages from coming to me. If anyone is wondering, this is what I have:

In php.ini: sendmail_path = '/mymail.pl'

mymail.pl:
Code:
#!/usr/bin/perl
use Mail::Address;

while (<STDIN>){
	$message.=$_;
}

($headers, $msg) = split(/\n\n/, $message);

@headers = split(/\n/, $headers);

foreach (@headers){
	if (/from:(.*)/ig){
		$from=$1;
	}
}

if ($from){
	@addrs = Mail::Address->parse($from);
	$addr=$addrs[0]->address;
}

if (!$addr){
	$addr='apache@somehost.com';
}

open MAIL, '|/usr/sbin/sendmail -t -i -f '.$addr;
print MAIL $message;
close (MAIL);

Works... I could do better, but I am lazy...

Thank you all for you help.

Brian


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top