Re: why is this not a bug? (popen, pclose)

From: Date: Fri, 14 Jul 2000 15:06:24 +0000
Subject: Re: why is this not a bug? (popen, pclose)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-6651@lists.php.net to get a copy of this message
> > You can always bypass mail() completely and do something like this > instead: > > <?php > > $fd = popen("/path/to/sendmail -oi -t -oeq", "w"); > > fwrite($fd, "From: Joe <joe@joe.com>\n"); > fwrite($fd, "To: Bob <bob@bob.com>\n"); > fwrite($fd, "Subject: blah blah\n"); > fwrite($fd, "\n"); > fwrite($fd, "my message, etc...\n"); > > pclose($fd); > > ?> > > If *that* doesn't work (minus any syntax errors of course :) there is > something really wrong with your system... you could easily put that in a > function that mimiced mail()'s arguments and be on your way... > > -philip > > interesting - I tried the following modification of the script you supplied: <?php $fd = popen("/usr/sbin/sendmail -oi -t -oeq", "w"); print "$fd was the result<BR>"; print "write from was " . fwrite($fd, "From: Dan <root@e-sci.com>\n"); print "write to was " . fwrite($fd, "To: Dan <omnivore@sympatico.ca>\n"); print "write subject was " . fwrite($fd, "Subject: hello dan\n"); print "write blank line was " . fwrite($fd, "\n"); print "write message was " . fwrite($fd, "this is the funky message\n"); $x = pclose($fd); print "hello there $x"; ?> which returns the following to the browser: > Resource id #1 was the result > write from was 27write to was 32write subject was 19write blank line was 1write message was 26hello there 512 the manual indicates for fopen that: > > If the open fails, the function returns false. which it isn't doing, so presumably there is something there to write to. But what is that value 'Resource id #1'? I can't find any documentation on it. The manual pages don't indicate what the value returned by fwrite means, but it seems safe to assume that it indicates how many characters were successfully written to the file - which indicates that it is indeed opening sendmail and writing to it, does it not? The manual then indicates for fclose tha: > >Returns true on success and false on failure. Since 512 is not false, the entire process succeeded, right? Although why 512 and not some other more obvious true value has me stumped... Now, I still don't get mail. So what gives? Does this simply mean that sendmail will return a code to php indicating success, for a process that fails/never takes place? And so its therefore a sendmail problem? Or does it indicate that php is misunderstanding the codes returned to it somehow? I would think that in an explicit process like this, that I would have some useful returned values to at least branch on... but this doesn't appear to be the case... dan ----------------------------------------------------- omnivore: omnivore@sympatico.ca Networked and Desktop interactive technologies tel: +1 416 603 3309 Build surveys online with surveys123: http://www.surveys123.com Your Online Science & Astronomy Superstore: http://www.e-sci.com

« previous php.general (#6651) next »