# Win32 mail() issue and potential fix - needs better brains than me to verify solution.

- Thread: https://externals.io/message/37069
- Original archive: https://news-web.php.net/php.internals/37069
- Started by Richard Quadling on 2008-04-17T14:43:43+00:00
- Messages: 4
- 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

---

## #37069 — Richard Quadling — 2008-04-17T14:43:43+00:00

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

Hi.

I have finally managed to get php to compile for windows (yippee for me).

So I can now try and get `mail()` working again.

The issue is that in  ext/standard/mail.c (/* $Id: mail.c,v
1.87.2.1.2.7.2.3 2007/12/31 07:17:15 sebastian Exp $ */), line 197,
the test of ...

if (!sendmail_path)

always evaluates to false when there is no sendmail_path which would
be the case on windows.

The next line differentiates between processing for windows/netware
and everything else.

If the test is

if(0 == strlen(sendmail_path))

then that would work.

The INI_STR call in Line 194 always returns a string if the directive
is known (doesn't need to be set, just has to exist as a directive).

So, I've attached a patch which I have compiled and tested on Windows.

This is in relation to bug http://bugs.php.net/bug.php?id=43348


Index: mail.c
===================================================================
RCS file: /repository/php-src/ext/standard/mail.c,v
retrieving revision 1.87.2.1.2.7.2.3
diff -u -u -r1.87.2.1.2.7.2.3 mail.c
--- mail.c	31 Dec 2007 07:17:15 -0000	1.87.2.1.2.7.2.3
+++ mail.c	17 Apr 2008 14:40:33 -0000
@@ -194,7 +194,7 @@
 	char *sendmail_path = INI_STR("sendmail_path");
 	char *sendmail_cmd = NULL;

-	if (!sendmail_path) {
+	if (0 == strlen(sendmail_path)) {
 #if (defined PHP_WIN32 || defined NETWARE)
 		/* handle old style win smtp sending */
 		if (TSendMail(INI_STR("SMTP"), &tsm_err, &tsm_errmsg, headers,
subject, to, message, NULL, NULL, `NULL` TSRMLS_CC) == FAILURE) {



-- 
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"

---

## #37085 — Scott MacVicar — 2008-04-17T16:59:12+00:00

URL: https://externals.io/message/37069#37085 · In reply to: #37069

Hi Richard,

The patch would fix it in this case but there is an underlying change 
that needs sorted.

zend_ini_string()'s behaviour was changed to fix 
http://bugs.php.net/bug.php?id=42657 so that if the default value was 
 `NULL` it would then return an empty string instead.

http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_ini.c?r1=1.39.2.2.2.18.2.6&r2=1.39.2.2.2.18.2.7

This broke the places that were relying on INI_STR returning the NULL?

Should this fix be backed out and change ini_get and ini_set to deal 
with this for the userland?

Scott

Richard Quadling wrote:
> Hi.
> 
> I have finally managed to get php to compile for windows (yippee for me).
> 
> So I can now try and get `mail()` working again.
> 
> The issue is that in  ext/standard/mail.c (/* $Id: mail.c,v
> 1.87.2.1.2.7.2.3 2007/12/31 07:17:15 sebastian Exp $ */), line 197,
> the test of ...
> 
> if (!sendmail_path)
> 
> always evaluates to false when there is no sendmail_path which would
> be the case on windows.
> 
> The next line differentiates between processing for windows/netware
> and everything else.
> 
> If the test is
> 
> if(0 == strlen(sendmail_path))
> 
> then that would work.
> 
> The INI_STR call in Line 194 always returns a string if the directive
> is known (doesn't need to be set, just has to exist as a directive).
> 
> So, I've attached a patch which I have compiled and tested on Windows.
> 
> This is in relation to bug http://bugs.php.net/bug.php?id=43348
> 
> 
> Index: mail.c
> ===================================================================
> RCS file: /repository/php-src/ext/standard/mail.c,v
> retrieving revision 1.87.2.1.2.7.2.3
> diff -u -u -r1.87.2.1.2.7.2.3 mail.c
> --- mail.c	31 Dec 2007 07:17:15 -0000	1.87.2.1.2.7.2.3
> +++ mail.c	17 Apr 2008 14:40:33 -0000
> @@ -194,7 +194,7 @@
>  	char *sendmail_path = INI_STR("sendmail_path");
>  	char *sendmail_cmd = NULL;
> 
> -	if (!sendmail_path) {
> +	if (0 == strlen(sendmail_path)) {
>  #if (defined PHP_WIN32 || defined NETWARE)
>  		/* handle old style win smtp sending */
>  		if (TSendMail(INI_STR("SMTP"), &tsm_err, &tsm_errmsg, headers,
> subject, to, message, NULL, NULL, `NULL` TSRMLS_CC) == FAILURE) {

---

## #37093 — Jani Taskinen — 2008-04-17T17:19:24+00:00

URL: https://externals.io/message/37069#37093 · In reply to: #37085

> Hi Richard,
> 
> The patch would fix it in this case but there is an underlying change 
> that needs sorted.
> 
> zend_ini_string()'s behaviour was changed to fix 
> http://bugs.php.net/bug.php?id=42657 so that if the default value was 
> `NULL` it would then return an empty string instead.
> 
> http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_ini.c?r1=1.39.2.2.2.18.2.6&r2=1.39.2.2.2.18.2.7
> 
> This broke the places that were relying on INI_STR returning the NULL?

Propably, but INI_STR is evil and should never be used anyway. 

> Should this fix be backed out and change ini_get and ini_set to deal 
> with this for the userland?

Hell no. Fix places using INI_STR incorrectly instead.
(as in: make them NOT use INI_STR.. :)

--Jani

---

## #37181 — Scott MacVicar — 2008-04-22T18:02:48+00:00

URL: https://externals.io/message/37069#37181 · In reply to: #37093

Jani Taskinen wrote:
> 
> > […]
> 
> Propably, but INI_STR is evil and should never be used anyway. 
> 
> > […]
> 
> Hell no. Fix places using INI_STR incorrectly instead.
> (as in: make them NOT use INI_STR.. :)
> 
> --Jani
> 
> 
> 

What is the alternative to INI_STR if you just want the value?

Scott
