Re: Update to mail() function help
| From: | Sara Golemon | Date: | Fri, 23 May 2003 23:40:29 +0000 |
| Subject: | Re: Update to mail() function help | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-1960@lists.php.net to get a copy of this message | ||
I recall this conversation comming up a month or two ago, this exact usage
in fact...
The best solution (albiet an ugly one) was to use zend_eval_str() to
"evaluate" an interpolated string:
if (zend_eval_str("\"{$_SERVER['SERVER_NAME']}\"", &tmpzval,
"server_name"
TSRMLS_CC) == SUCCESS) {
foo = Z_STRVAL(tmpzval);
} else {
foo = NULL;
}
Or something close to that, I havn't had cause to use zend_eval_str so I'm
not sure about the exact code needed...
"Rasmus Lerdorf" <rasmus@lerdorf.com> wrote in message
news:Pine.LNX.4.44.0305231622560.1158-100000@thinkpad.lerdorf.com...
> I am not saying that is a bad idea, just that in this case what he wants
> to add is not just a static string, but the current server name. If we
> could do variable expansion at runtime from ini directives then this would
> fit perfectly.
>
> -Rasmus
>
> On Sat, 24 May 2003, Jani Taskinen wrote:
>
> >
> > Oh well, just thought about more general solution. :)
> > Someone might want to add some other headers too.
> >
> > --Jani
> >
> >
> > On Fri, 23 May 2003, Rasmus Lerdorf wrote:
> >
> > >That would require a different ini setting for each virtual server and
> > >thus could be a lot more work than just hacking the code.
> > >
> > >On Sat, 24 May 2003, Jani Taskinen wrote:
> > >
> > >>
> > >> Maybe a php.ini option would be best for this?
> > >> Like mail.extra_headers or something alike..?
> > >> ie. that would add the specified headers to every
> > >> mail sent with mail().
> > >>
> > >> --Jani
> > >>
> > >>
> > >> On Fri, 23 May 2003, Rasmus Lerdorf wrote:
> > >>
> > >> >To access $_SERVER['SERVER_NAME'] from C you would do:
> > >> >
> > >> >zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]->value.ht,
"SERVER_NAME", sizeof("SERVER_NAME"), (void **) &server_name)==FAILURE)
> > >> >
> > >> >But, if variables_order doesn't include "S" it isn't
> > >> >going to be
there.
> > >> >You are probably better off getting it directly from the server
instead of
> > >> >from the PHP symbol table. You can call php_apache_getenv()
directly, or
> > >> >to be more correct and portable to other SAPI's you would call
> > >> >sapi_module.getenv().
> > >> >
> > >> >-Rasmus
> > >> >
> > >> >
> > >> >On Fri, 23 May 2003, Patrick Gibson wrote:
> > >> >
> > >> >> I'd like modify the PHP mail() function to add the
$_SERVER['SERVER_NAME']
> > >> >> into the header if it's available. It would be equivalent to
adding a line
> > >> >> into the headers argument from the PHP end that would be like:
> > >> >>
> > >> >> if ($_SERVER['SERVER_NAME'])
> > >> >> {
> > >> >> $headers .= '\nX-Originated-From: www.mywebsite.com';
> > >> >> }
> > >> >>
> > >> >> I see exactly in ext/standard/mail.c where I need to add this, but
my
> > >> >> problem is I'm not sure how to gain access to the $_SERVER super
global
> > >> >> array from the C API.
> > >> >>
> > >> >> Can anyone point me in the right direction? I don't see anything
in the API
> > >> >> docs that explains this, nor can I think of any PHP function that
does
> > >> >> something like this for a reference (except phpinfo(), but the
code is
> > >> >> unclear to me).
> > >> >>
> > >> >> I run a hosting company, and if any of our customers abuses this
function, I
> > >> >> want to be able to know from which website the mail originated.
When there
> > >> >> are hundreds of virtual hosts, something like this would make it
really
> > >> >> helpful at times.
> > >> >>
> > >> >> Thanks so much,
> > >> >>
> > >> >> Patrick
> > >> >>
> > >> >>
> > >> >>
> > >> >
> > >> >
> > >> >
> > >>
> > >>
> > >
> > >
> > >
> >
> >
>