# vhost in mail

- Thread: https://externals.io/message/13674
- Original archive: https://news-web.php.net/php.internals/13674
- Started by Alexander Windbichler on 2004-11-01T17:02:54+00:00
- Messages: 5
- 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

---

## #13674 — Alexander Windbichler — 2004-11-01T17:02:54+00:00

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

Hello,

in the `phpinfo()` I can find (apache2handler) the entry: "Hostname:Port",
which displays the vhost you are running the script from.
In [phpsources]/sapi/apache2handler/php_functions.c I found the source. Now
I want to display the vhost in every mail, which is sent by php. I know that
the source is in [phpsources]/ext/standard/mail.c and I know how to add a
simple text, but I don't know how to insert the vhost.

Can someone help me please?

best regards,
Alex

---

## #13676 — Sara Golemon — 2004-11-01T18:53:10+00:00

URL: https://externals.io/message/13674#13676 · In reply to: #13674

> in the `phpinfo()` I can find (apache2handler) the entry: "Hostname:Port",
> which displays the vhost you are running the script from.
> In [phpsources]/sapi/apache2handler/php_functions.c I found the source.
Now
> I want to display the vhost in every mail, which is sent by php. I know
that
> the source is in [phpsources]/ext/standard/mail.c and I know how to add a
> simple text, but I don't know how to insert the vhost.
>

With two HUGE caveats:

Index: ext/standard/mail.c
===================================================================
RCS file: /repository/php-src/ext/standard/mail.c,v
retrieving revision 1.84
diff -u -r1.84 mail.c
--- ext/standard/mail.c 25 Sep 2004 14:48:44 -0000      1.84
+++ ext/standard/mail.c 1 Nov 2004 18:50:16 -0000
@@ -180,6 +180,7 @@
        int ret;
        char *sendmail_path = INI_STR("sendmail_path");
        char *sendmail_cmd = NULL;
+    server_rec *serv = ((php_struct *) SG(server_context))->r->server;

        if (!sendmail_path) {
 #if (defined PHP_WIN32 || defined NETWARE)
@@ -229,6 +230,8 @@
 #endif
                fprintf(sendmail, "To: %s\n", to);
                fprintf(sendmail, "Subject: %s\n", subject);
+               fprintf(sendmail, "X-Server-Hostname: %s\n",
serv->server_hostname);
+               fprintf(sendmail, "X-Server-Port: %d\n", serv->port);
                if (headers != NULL) {
                        fprintf(sendmail, "%s\n", headers);



#1) Assumes Apache2handler (probably fine since you'll be doing this on your
server only)
#2) Havn't tested it.  Use at your own risk.  No warranties either expressed
or implied.

-Sara

---

## #13678 — Paul G — 2004-11-01T19:11:25+00:00

URL: https://externals.io/message/13674#13678 · In reply to: #13674

----- Original Message ----- 
From: "Alexander Windbichler" <A.Windbichler@cybton.com>
To: <internals@lists.php.net>
Sent: Monday, November 01, 2004 12:02 PM
Subject: [PHP-DEV] vhost in mail


> Hello,
>
> in the `phpinfo()` I can find (apache2handler) the entry: "Hostname:Port",
> which displays the vhost you are running the script from.
> In [phpsources]/sapi/apache2handler/php_functions.c I found the source.
Now
> I want to display the vhost in every mail, which is sent by php. I know
that
> the source is in [phpsources]/ext/standard/mail.c and I know how to add a
> simple text, but I don't know how to insert the vhost.
>
> Can someone help me please?

i posted a patch that inserts the script path for abuse tracking purposes to
this list a while back. this was sufficient for my purposes, since in our
setup the directory structure maps one to one to the vhosts. there is also a
more complete patch floating around that inserts pretty much everything you
may want to see and is being used in production by a few people. i'll see if
i can dig it up, but i know it can be googled.

paul

---

## #13831 — Alexander Windbichler — 2004-11-13T22:51:38+00:00

URL: https://externals.io/message/13674#13831 · In reply to: #13676

Hello,

sorry for the late reply.

I tried to patch php like:

cat patch | patch -p1
then I filed in the patch manually, but it will not work.

Error:

debian:/usr/src/php-5.0.2# cat b | patch -p1
can't find file to patch at input line 4
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff -u -r1.84 mail.c
|--- ext/standard/mail.c 25 Sep 2004 14:48:44 -0000      1.84
|+++ ext/standard/mail.c 1 Nov 2004 18:50:16 -0000
--------------------------
File to patch: ext/standard/mail.c
patching file ext/standard/mail.c
Hunk #1 FAILED at 180.
1 out of 1 hunk FAILED -- saving rejects to file ext/standard/mail.c.rej
missing header for unified diff at line 13 of patch
can't find file to patch at input line 13
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|
--------------------------
File to patch: ext/standard/mail.c
patching file ext/standard/mail.c
Hunk #1 FAILED at 230.
1 out of 1 hunk FAILED -- saving rejects to file ext/standard/mail.c.rej
You have new mail in /var/mail/root
debian:/usr/src/php-5.0.2#


I've never patched PHP, sorry for the question.

alex

"Sara Golemon" <pollita@php.net> schrieb im Newsbeitrag
news:20041101185355.68675.qmail@pb1.pair.com...
> > […]
> Now
> > […]
> that
> > […]
a
> > […]
>
> With two HUGE caveats:
>
> Index: ext/standard/mail.c
> ===================================================================
> RCS file: /repository/php-src/ext/standard/mail.c,v
> retrieving revision 1.84
> diff -u -r1.84 mail.c
> --- ext/standard/mail.c 25 Sep 2004 14:48:44 -0000      1.84
> +++ ext/standard/mail.c 1 Nov 2004 18:50:16 -0000
> @@ -180,6 +180,7 @@
>         int ret;
>         char *sendmail_path = INI_STR("sendmail_path");
>         char *sendmail_cmd = NULL;
> +    server_rec *serv = ((php_struct *) SG(server_context))->r->server;
>
>         if (!sendmail_path) {
>  #if (defined PHP_WIN32 || defined NETWARE)
> @@ -229,6 +230,8 @@
>  #endif
>                 fprintf(sendmail, "To: %s\n", to);
>                 fprintf(sendmail, "Subject: %s\n", subject);
> +               fprintf(sendmail, "X-Server-Hostname: %s\n",
> serv->server_hostname);
> +               fprintf(sendmail, "X-Server-Port: %d\n", serv->port);
>                 if (headers != NULL) {
>                         fprintf(sendmail, "%s\n", headers);
>
>
>
> #1) Assumes Apache2handler (probably fine since you'll be doing this on
your
> server only)
> #2) Havn't tested it.  Use at your own risk.  No warranties either
expressed
> or implied.
>
> -Sara

---

## #13870 — Sara Golemon — 2004-11-15T18:53:44+00:00

URL: https://externals.io/message/13674#13870 · In reply to: #13831

> I tried to patch php like:
>
> cat patch | patch -p1
> then I filed in the patch manually, but it will not work.
>
> Error:
>
*shrug*... didn't give me issues, but why not just edit the files directly,
the patch is tiny enough....


1) Open up ext/standard/mail.c in your favorite editor
2) Look for lines similar to the following somewhere around line 180:
         int ret;
         char *sendmail_path = INI_STR("sendmail_path");
         char *sendmail_cmd = NULL;

         if (!sendmail_path) {
  #if (defined PHP_WIN32 || defined NETWARE)

3) Add in this line at the end of the variable declaration block:
    server_rec *serv = ((php_struct *) SG(server_context))->r->server;

4) Go down a few lines (somewhere around line 229) and look for:
 #endif
                fprintf(sendmail, "To: %s\n", to);
                fprintf(sendmail, "Subject: %s\n", subject);
                if (headers != NULL) {
                        fprintf(sendmail, "%s\n", headers);


5) Then add in this just after the Subject: line:
              fprintf(sendmail, "X-Server-Hostname: %s\n",
serv->server_hostname);
              fprintf(sendmail, "X-Server-Port: %d\n", serv->port);


Congrats, you just learned how to read a patch file!

-Sara
