php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #29629 mail() on unix is unable to use external SMTP server
Submitted: 2004-08-12 11:32 UTC Modified: 2022-04-08 07:47 UTC
Votes:19
Avg. Score:4.5 ± 0.8
Reproduced:17 of 18 (94.4%)
Same Version:6 (35.3%)
Same OS:8 (47.1%)
From: mymaillists at gmx dot at Assigned: ilutov (profile)
Status: Closed Package: Mail related
PHP Version: Irrelevant OS: all unixes
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mymaillists at gmx dot at
New email:
PHP Version: OS:

 

 [2004-08-12 11:32 UTC] 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:
----------------
 


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-03-14 13:18 UTC] dexter at debian dot org
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 = me@example.com 
 
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);
 [2016-12-30 19:02 UTC] cmb@php.net
-Package: Feature/Change Request +Package: Mail related
 [2019-09-06 09:32 UTC] alien at rmail dot be
would be very useful considering the recent trend of containerization.
 [2021-07-26 13:30 UTC] cmb@php.net
> would be very useful considering the recent trend of
> containerization.

Then someone should provide a pull request[1].

[1] <https://github.com/php/php-src/pulls>
 [2022-04-08 07:47 UTC] ilutov@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: ilutov
 [2022-04-08 07:47 UTC] ilutov@php.net
We're closing all feature requests from bugs.php.net. Please create an issue or PR on GitHub if this is still relevant.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 13:01:30 2024 UTC