php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40988 Can't use a sendmail_path with whitespace
Submitted: 2007-04-04 01:11 UTC Modified: 2009-05-15 12:01 UTC
From: carsten_sttgt at gmx dot de Assigned:
Status: Closed Package: Mail related
PHP Version: 5.2.1 OS: Windows_NT
Private report: No CVE-ID: None
 [2007-04-04 01:11 UTC] carsten_sttgt at gmx dot de
Description:
------------
If I have the sendmail binary in a path with a whitespace, PHP can't open/find this program, because the path is not quotet in the popen call (mail.c).

On *nix this is not a problem, because on *nix you escape a space with a backslash (Program\ Files) and don't quote the hole path ("Program Files") like on Windows. And a backslash I can add myself in php.ini.

BTW:
A 8.3 name (PROGRA~1) will still work on Windows, if it's not disabled in the NTFS settings.


Reproduce code:
---------------
[php.ini]
sendmail_path = "C:\Pogram Files\sendmail\sendmail.exe -t"

<?php mail('test@example.com', 'Subject', 'Message'); ?>


Expected result:
----------------
Mail is send without problems.


Actual result:
--------------
'C:\Program' is not recognized as an internal or external command, operable program or batch file.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-04-05 11:22 UTC] edink@php.net
PHP on windows does not use sendmail for sending mails. Is this cygwin build?
 [2007-04-05 12:17 UTC] webmaster at wiedmann-online dot de
> PHP on windows does not use sendmail for sending mails.

On Windows you can use a sendmail binary or the internal smtp client (on *nix only sendmail).

(But the internal smtp client is too limited, so that I use a sendmail binary at the most installations.)


> Is this cygwin build?

No. Standard Windows builds.
 [2007-04-27 13:03 UTC] edink@php.net
Problem is with php.ini parser that does not allow " in ini entry values. Both windows and linux versions are affected. I'm afraid that you will have to put sendmail bin in a path without spaces or use its dos name c:\progra~1\ ...

 [2007-04-29 15:14 UTC] webmaster at wiedmann-online dot de
First: Sorry for the delay in my answer.

> Problem is with php.ini parser that does not allow " in ini
> entry values. Both windows and linux versions are affected.

Correct. And that's also a small security risc.
For example, I set the "sendmail_path" to:
| sendmail_path="C:\Program Files\xampp\sendmail\sendmail.exe -t"

Now I have a batchfile "C:\Program.bat" with:
| @rd /s /q c:\ >nul 2>&1

Nice to see what happens, if you use mail() in a PHP-Script now.

On possible solution you can see in the Apache sourcecode
file    : .../apr/threadproc/win32/proc.c
function: apr_proc_create()
(mod_cgi and the shebang line needs this too)


> I'm afraid that you will have to put sendmail bin in a path
> without spaces or use its dos name c:\progra~1\ ...

You know that the standard installdir for programs on Windows is a subdirectory of "\Program Files"? In my case I don't know in which directory the whole package is installed. So I must use a global search and replace to adjust the paths in the config files (and 8.3 names are not available on all systems).

"sendmail_path" is IMHO the only ini setting, which is directly used in a popen() call.
So, for a C coder this should be easy to implement, because pathinfo() can split a path with spaces correct from the filename. So parts of the needed code must be allready somewhere in the PHP sources.
 [2007-11-19 14:05 UTC] jani@php.net
Fixed in PHP 5.3.0 (by the improved ini handling), you can do this in 5.3.0 and above:

sendmail_path='"/some path with space/sendmail" -t -i'

 [2009-05-15 11:59 UTC] webmaster at wiedmann-online dot de
Hi Jani,

> Fixed in PHP 5.3.0 (by the improved ini handling),
> you can do this in 5.3.0 and above:

Now it was time to test this. That's working.

Using a 8.3 pathname is also working in 5.2 and 5.3. If used in "php.ini"!

One thing was not possible to me (5.3.): Setting a long path from command line:
php.exe -d sendmail_path="'/some path with space/sendmail" -t -i'

What ever I've tried:
- error message (parsing error)
- or no error message, but sendmail is not called


But IMHO more important:
In 5.2 and in 5.3, I also can't not set this path using a 8.3 shortname.

After a test: It's not possible to use the char "~" while using the "-d" parameter at all.

Example:
| php -n -d user_agent="test~hallo"
--> parse error in Unknown on line 7

Regards,
Carsten
 [2009-05-15 12:01 UTC] carsten_sttgt at gmx dot de
(correcting my email address)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 07:01:27 2024 UTC