Re: Update to mail() function help

From: Date: Sun, 25 May 2003 19:22:58 +0000
Subject: Re: Update to mail() function help
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-1996@lists.php.net to get a copy of this message
"Patrick Gibson" <php.dev@patrickg.com> a écrit dans le message news: BAF555C5.C868%php.dev@patrickg.com... > Hi Rasmus, I'm having a (likely) small problem here. I just preface this > problem with the fact that I do not have a lot of C experience (which is the > cause of my problem) -- most of my experiences are in Java, PHP and the > like. > > I have added the following into php_mail() in mail.c: > > zval *server_name; > > <snip, snip...> > > fprintf(sendmail, "To: %s\n", to); > fprintf(sendmail, "Subject: %s\n", subject); Hey, fprintf is not strcat. You're just overwriting sendmail with all these fprints. Use strcat. > > zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]->value.ht, > "SERVER_NAME", sizeof("SERVER_NAME"), (void **) &server_name); > > if (server_name != NULL) > { > fprintf(sendmail, "X-Site-Origin: %s\n", server_name); You prolly need a convert_to_string_ex(server_name) before using it in the fprintf statement. > } > > The problem I'm not sure how to declare server_name because I'm not really > clear on what zend_hash_find() is expecting, and then if it will be > compatible with the fprintf() statement. I've tried a few different things > with the server_name declaration, but so far I haven't had any luck -- > server_name always comes out blank. > > I guess I'm used to online API documentation that outlines all the > functions, etc. I haven't been able to find anything yet with the Zend API > that provides a complete list what everything does. > > I also tried using php_apache_getenv() and sapi_module.getenv(), but I am > unclear of what I need to #include inside mail.c to get these to work. If I > can just get past this hurdle, I think I will start understanding things > much better. I'm really eager to learn as much C as possible, as I see it > opening many doors for me, but I'm finding things to be very different from > what I'm used to. If anyone has any recommendations on books for a good > introduction to C, perhaps with some Unix focus, I'd be very happy to hear > them. > > Thanks, > > Patrick Thank you, nicos. > > > On 5/23/03 13:30, 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 > >> > >> > >> > > > >

« previous php.internals (#1996) next »