# Update to mail() function help

- Thread: https://externals.io/message/1948
- Original archive: https://news-web.php.net/php.internals/1948
- Started by Patrick Gibson on 2003-05-23T19:51:34+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #1948 — Patrick Gibson — 2003-05-23T19:51:34+00:00

URL: https://externals.io/message/1948#1948

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

---

## #1949 — Rasmus Lerdorf — 2003-05-23T20:30:41+00:00

URL: https://externals.io/message/1948#1949 · In reply to: #1948

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




> 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
