ID: 29629 Comment by: dexter at debian dot org Reported By: mymaillists at gmx dot at Status: Open Bug Type: Feature/Change Request Operating System: all unixes PHP Version: Irrelevant New Comment:
It was my modification for mail() function. It requires the sendmail_path setting to be distabled and sendmail_from to be set. ; php.ini sendmail_path= sendmail_from = [EMAIL PROTECTED] The patch: diff -ru php-5.0.3.orig/ext/standard/config.m4 php-5.0.3/ext/standard/config.m4 --- php-5.0.3.orig/ext/standard/config.m4 2004-05-10 09:23:38 +0200 +++ php-5.0.3/ext/standard/config.m4 2005-03-11 22:14:01 +0100 @@ -469,6 +469,7 @@ incomplete_class.c url_scanner_ex.c ftp_fopen_wrapper.c \ http_fopen_wrapper.c php_fopen_wrapper.c credits.c css.c \ var_unserializer.c ftok.c sha1.c user_filters.c uuencode.c \ - filters.c proc_open.c sunfuncs.c streamsfuncs.c http.c) + filters.c proc_open.c sunfuncs.c streamsfuncs.c http.c \ + ../../win32/sendmail.c) PHP_ADD_MAKEFILE_FRAGMENT diff -ru php-5.0.3.orig/ext/standard/mail.c php-5.0.3/ext/standard/mail.c --- php-5.0.3.orig/ext/standard/mail.c 2005-03-11 23:17:23 +0100 +++ php-5.0.3/ext/standard/mail.c 2005-03-11 23:11:12 +0100 @@ -39,9 +39,7 @@ #include "exec.h" #if HAVE_SENDMAIL -#ifdef PHP_WIN32 #include "win32/sendmail.h" -#endif #ifdef NETWARE #include "netware/pipe.h" /* For popen(), pclose() */ @@ -175,17 +173,14 @@ */ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char *extra_cmd TSRMLS_DC) { -#if (defined PHP_WIN32 || defined NETWARE) int tsm_err; char *tsm_errmsg = NULL; -#endif FILE *sendmail; int ret; char *sendmail_path = INI_STR("sendmail_path"); char *sendmail_cmd = NULL; - if (!sendmail_path) { -#if (defined PHP_WIN32 || defined NETWARE) + if (!sendmail_path || !sendmail_path[0]) { /* handle old style win smtp sending */ if (TSendMail(INI_STR("SMTP"), &tsm_err, &tsm_errmsg, headers, subject, to, message, NULL, NULL, NULL) == FAILURE) { if (tsm_errmsg) { @@ -197,9 +192,6 @@ return 0; } return 1; -#else - return 0; -#endif } if (extra_cmd != NULL) { sendmail_cmd = emalloc (strlen (sendmail_path) + strlen (extra_cmd) + 2); @@ -272,15 +264,11 @@ { char *sendmail_path = INI_STR("sendmail_path"); -#ifdef PHP_WIN32 - if (!sendmail_path) { - php_info_print_table_row(2, "Internal Sendmail Support for Windows", "enabled"); + if (!sendmail_path || !sendmail_path[0]) { + php_info_print_table_row(2, "Internal Sendmail Support", "enabled"); } else { php_info_print_table_row(2, "Path to sendmail", sendmail_path); } -#else - php_info_print_table_row(2, "Path to sendmail", sendmail_path); -#endif } /* }}} */ diff -ru php-5.0.3.orig/win32/sendmail.c php-5.0.3/win32/sendmail.c --- php-5.0.3.orig/win32/sendmail.c 2003-12-08 23:10:42 +0100 +++ php-5.0.3/win32/sendmail.c 2005-03-11 23:01:28 +0100 @@ -22,19 +22,31 @@ #include "php.h" /*php specific */ #include <stdio.h> #include <stdlib.h> -#ifndef NETWARE +#ifdef PHP_WIN32 #include <winsock2.h> -#else /* NETWARE */ +#elifdef NETWARE #include <netware\sendmail_nw.h> -#endif /* NETWARE */ +#endif +#if PHP_WIN32 || NETWARE #include "time.h" +#else +#include <time.h> +#define _timezone __timezone +#include <resolv.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <net/if.h> +#include <netdb.h> +#define INVALID_SOCKET -1 +#endif #include <string.h> #include <math.h> -#ifndef NETWARE +#ifdef PHP_WIN32 #include <malloc.h> #include <memory.h> #include <winbase.h> -#endif /* NETWARE */ +#endif #include "sendmail.h" #include "php_ini.h" @@ -79,12 +91,20 @@ char Buffer[MAIL_BUFFER_SIZE]; /* socket related data */ -SOCKET sc; -#ifndef NETWARE +#if PHP_WIN32 || NETWARE +typedef SOCKET sc; +#else +int sc; +#endif +#ifdef PHP_WIN32 WSADATA Data; struct hostent *adr; #endif /* NETWARE */ +#if PHP_WIN32 || NETWARE SOCKADDR_IN sock_in; +#else +struct sockaddr_in sock_in; +#endif #ifndef NETWARE int WinsockStarted; /* values set by the constructor */ @@ -94,11 +114,7 @@ char LocalHost[HOST_NAME_LEN]; #endif char seps[] = " ,\t\n"; -#ifndef NETWARE -char *php_mailer = "PHP 4 WIN32"; -#else -char *php_mailer = "PHP 4 NetWare"; -#endif /* NETWARE */ +char *php_mailer = "PHP"; char *get_header(char *h, char *headers); @@ -227,7 +243,7 @@ char *headers_lc = NULL; /* headers_lc is only created if we've a header at all */ TSRMLS_FETCH(); -#ifndef NETWARE +#ifdef PHP_WIN32 WinsockStarted = FALSE; #endif @@ -333,7 +349,7 @@ */ shutdown(sc, 0); -#ifndef NETWARE +#ifdef PHP_WIN32 closesocket(sc); #else /* closesocket commented out since it was giving undefined symbol linker error @@ -805,9 +821,17 @@ /* Connect to server */ sock_in.sin_family = AF_INET; sock_in.sin_port = htons(portnum); +#if PHP_WIN32 || NETWARE sock_in.sin_addr.S_un.S_addr = GetAddr(MailHost); +#else + sock_in.sin_addr.s_addr = GetAddr(MailHost); +#endif +#if PHP_WIN32 || NETWARE if (connect(sc, (LPSOCKADDR) & sock_in, sizeof(sock_in))) +#else + if (connect(sc, & sock_in, sizeof(sock_in))) +#endif return (FAILED_TO_CONNECT); /* receive Server welcome message */ @@ -828,7 +852,7 @@ // Author/Date: jcar 20/9/96 // History: //********************************************************************/ -#ifndef NETWARE +#ifdef PHP_WIN32 int Post(LPCSTR msg) #else int Post(char *msg) @@ -919,13 +943,17 @@ // Author/Date: jcar 20/9/96 // History: //********************************************************************/ -#ifndef NETWARE +#ifdef PHP_WIN32 unsigned long GetAddr(LPSTR szHost) #else unsigned long GetAddr(char * szHost) #endif { +#if PHP_WIN32 || NETWARE LPHOSTENT lpstHost; +#else + struct hostent *lpstHost; +#endif u_long lAddr = INADDR_ANY; /* check that we have a string */ @@ -937,9 +965,13 @@ /* If not an address, then try to resolve it as a hostname */ if ((lAddr == INADDR_NONE) && (strcmp(szHost, "255.255.255.255"))) { +#if PHP_WIN32 || NETWARE lpstHost = gethostbyname(szHost); +#else + lpstHost = gethostbyname(szHost); +#endif if (lpstHost) { /* success */ -#ifndef NETWARE +#ifdef PHP_WIN32 lAddr = *((u_long FAR *) (lpstHost->h_addr)); #else lAddr = *((u_long *) (lpstHost->h_addr)); diff -ru php-5.0.3.orig/win32/sendmail.h php-5.0.3/win32/sendmail.h --- php-5.0.3.orig/win32/sendmail.h 2003-12-08 23:10:42 +0100 +++ php-5.0.3/win32/sendmail.h 2005-03-11 22:12:04 +0100 @@ -1,6 +1,6 @@ #if !defined(sendmail_h) /* Sentry, use file only if it's not already included. */ #define sendmail_h -#ifndef NETWARE +#ifdef PHP_WIN32 #include <windows.h> #endif @@ -44,13 +44,13 @@ int MailConnect(); int PostHeader(char *, char *, char *, char *); -#ifndef NETWARE +#ifdef PHP_WIN32 int Post(LPCSTR msg); #else int Post(char *msg); #endif int Ack(char **server_response); -#ifndef NETWARE +#ifdef PHP_WIN32 unsigned long GetAddr(LPSTR szHost); #else unsigned long GetAddr(char * szHost); Previous Comments: ------------------------------------------------------------------------ [2004-08-12 11:32:40] mymaillists at gmx dot at Description: ------------ Not really a bug but a serious design error. We use php 4.3.8 (tried 5.0 too) on Unixes (AIX, Solaris, Linux) and need to move the apache server onto a machine that will run only apache and php, and that into a chrooted jail for security reasons. We have numerous php scripts that use the mail() function and have discovered that on Unixes, php will only use a locally installed MTA that is directly callable (sendmail, qmail, ...), and that PHP on unix is hard coded so that it can not use an external SMTP server. Changing the configuration in the php.ini file achieves nothing. PHP on windows however is able to use an external SMTP server. It should be possible to configure PHP on unix systems so that it can use an external SMTP server and not need a locally installed MTA such as sendmail. It would also be useful if PHP supported authentication when connecting to an external SMTP server. These changes would enable significant improvements in the security of systems on which apache/php run. Reproduce code: --------------- no code necessary Expected result: ---------------- ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=29629&edit=1