php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30647 mail() keeps script running however initiates mailwrapper
Submitted: 2004-11-01 12:28 UTC Modified: 2005-01-20 20:39 UTC
From: jurgen at person dot be Assigned:
Status: Not a bug Package: Mail related
PHP Version: 5.0.2 OS: FreeBSD
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jurgen at person dot be
New email:
PHP Version: OS:

 

 [2004-11-01 12:28 UTC] jurgen at person dot be
Description:
------------
I have a problem with the PHP mail() function on a running Qmail server
on FreeBSD 5.2.1.  Pretty like this problem, I found in the mail archive : 
http://lists.freebsd.org/pipermail/freebsd-questions/2003-August/017231.html

Would You PLEASE set the solution somewhere on the php.net documentation, because 
this problem returns very often.  I knew once the solution, but I forgot to take
notes.

OS			 : FreeBSD 5.2.1
Mailserver: Qmail
PHP       : 5.0.2 (4.3.9 same error)

Step 1: Testing of the qmail server in shell:

I create a test.eml file with:
<snip>
Message-ID: <802973227.20041027110037@person.be>
Date: Wed, 27 Oct 2004 11:00:37 +0200
From: me <me@mydomain.loc>
To: me2@mydomain.loc
Subject: Local test
 
Helleuu.
</snip>

I test the mailserver from shell with:
cat test.eml | /var/qmail/bin/qmail-inject      (mail arrives)
cat test.eml | /usr/sbin/sendmail -t -i			(mail arrives)
mail -s "test" me@mydomain.loc < test.eml       (mail arrives)

Step 2: I deinstalled the whole bunch of PHP 4.3.9 with:
pkg_delete -x "php4*"
pkg_delete -x "pecl-*"
rm -d -r /usr/local/lib/php /usr/local/include/php

Step 3: Install minimum PHP system.

cd /usr/ports/lang/php5
make WITH_APACHE=yes PHP_SAPI=full
make WITH_APACHE=yes  PHP_SAPI=full install

Step 4: Configure right php.ini and verify it works

cp /usr/local/etc/php.ini-dist /usr/local/etc/php.ini

Change 
;sendmail_path
into
sendmail_path = /var/qmail/bin/qmail-inject

(note: same behaviour when i use, or I use ; before sendmail)
sendmail_path = /usr/sbin/sendmail -t -i 

qmail-inject can be accessed and executed from others.

Write a test.php with
<?
	phpinfo();
?>

# php -v
PHP 5.0.2 (cli) (built: Oct 31 2004 11:12:24) (DEBUG)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.2, Copyright (c) 1998-2004 Zend Technologies

(Ok next time i try WITH_DEBUG=no)

#php -m
[PHP Modules]
libxml
SPL
Standard

#php -f test.php | grep sendmail_path
sendmail_path => /var/qmail/bin/qmail-inject =>
/var/qmail/bin/qmail-inject

(Ok, seems OK)

Step 5: testing mail from PHP

A simple test2.php:
<? mail("me@mydomain.loc", "Subjet", "Test mail"); ?>

#php -f test2.php

->Same results, the script sits waiting/running whatever.
No core dumped, it just runs and waits...

Step 6: Let the script run and try another session

ps -aux and i have this:

(using mailwrapper)
root        8803  0.0  0.9  6152 3440  p0  I+    4:44PM   0:00.17 php -f test2.php
root        8804  0.0  0.1   908  332  p0  I+    4:44PM   0:00.02 sh -c /usr/sbin/sendmail -t -i
root        8805  0.0  0.2  1256  584  p0  I+    4:44PM   0:00.08 bin/qmail-inject -H --
qmailq      8806  0.0  0.1  1224  512  p0  I+    4:44PM   0:00.04 bin/qmail-queue

So the script initiates the wrapper; qmail-inject and qmail-queue)

(using qmailinject directly from php.ini)
root        8962  0.0  0.9  6152 3440  p1  I+    5:00PM   0:00.16 php -f testmail.php
root        8963  0.0  0.1   908  332  p1  I+    5:00PM   0:00.02 sh -c /var/qmail/bin/qmail-inject
root        8964  0.0  0.2  1256  584  p1  I+    5:00PM   0:00.03 /var/qmail/bin/qmail-inject
qmailq      8965  0.0  0.1  1224  512  p1  I+    5:00PM   0:00.03 bin/qmail-queue

In this case the script initiates qmail-inject directly and qmail-queue)

But why does it stucks, waits and the phpscript keeps running ? 

Step 7: Use qmail-inject directly with printout to screen option

Change php.ini with 
sendmail_path = /var/qmail/bin/qmail-inject -H -n


#php -f test2.php
Return-Path: <my-mail>
Date: 31 Oct 2004 16:59:51 -0000
Message-ID: <20041031165951.9252.qmail@mydomain>
From: mymail
To: jurgen@person.be
Subject: Subjet


 
Test mail

(and the script does NOT return to the promp)

Step 8: Verify what's going on with qmail-stat in a seconday shell

#/var/qmail/bin/qmail-qstat
messages in queue: 4

--> when the script is started it is raised  +1
--> when teh script is stopped it is lowered -1

So the mail get stucks into the queue and refuse to be processed further.
What to do ?!

Expected result:
----------------
The mail() function should handle more deeple the mail process.  We looked to phpmailer.sourceforge.net  Maybe this would be a better solution to invake it owns SMTP protocol.
Or maybe it should be used as extension.

Anyway mail() should never hang/deadloop a script, running from the prompt.  It should catch the reason why it does not succeed.

So I think it's related to the communication between mail() and the mailserver, because the mail() sits to wait for 'something' before it continues it scripts.  Maybe the pipe is broken, the handle is closed.  But I would known the reason, because this event returns, and returns on questions and should be made public on the documentation.

Actual result:
--------------
How do You do backtracing from shellprompt ?!

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-19 19:07 UTC] sniper@php.net
It's obviously not any bug in mail() but just some configuration issue with qmail. (mail() was meant to be used with sendmail, with anything else: your mileage will vary)

As you said: "I knew once the solution, but I forgot
to take notes."

Try google.

 [2005-01-20 20:39 UTC] jurgen at person dot be
Yeah, and my Granny is Margaret Tatcher.

It has nothing to do with Qmail.  Qmail runs just fine
on the server and if You look to my tests, You can see the problem is not in that direction.  I even exclude the use of the mailwrapper.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Aug 10 23:05:51 2022 UTC