PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Mail » Mail » Bug #3158

exit code for Mail::Sendmail->send not detected correctly

Details

Submitted2005-01-11 01:04 UTC
Fromcbs at cts dot ucla dot edu
Assignedchagenbu
StatusClosed
PackageMail
PHP Version4.3.10
OSlinux
Roadmaps(Not assigned)

Comments

[2005-01-11 01:04 UTC] cbs at cts dot ucla dot edu

Description:
------------
This applies, at least, to Mail 1.1.4, and possibly earlier versions.

The exit code for Mail::Sendmail->send is not properly detected. circa line 125 of Mail/Sendmail.php:

$mail = popen($this->sendmail_path . (!empty($this->sendmail_args) ? ' ' . $this->sendmail_args : '') . " -f$from -- $recipients", 'w');
fputs($mail, $text_headers);
fputs($mail, $this->sep); // newline to end the headers section
fputs($mail, $body);
$result = pclose($mail) >> 8 & 0xFF; // need to shift the pclose result to get the exit code

pclose() is defined as returning the termination status of the process that was run. Shifting it 8 bits and anding with FF causes all results to be 0. The code should be

$result = pclose($mail);

Reproduce code:
---------------
using sendmail: as root, chmod 700 /var/log/clientmqueue (or misconfigure sendmail in some way so that it will exit non-zero) and run:

<?php
include_once 'Mail.php';
$mailer = &Mail::factory('sendmail', '');
$result = $mailer->send('nobody',
array('From' => 'nobody', 'To' => nobody'), "test\n");
if (PEAR::isError($result)) echo $result->getMessage()."\n";
else echo "good\n";
?>

Expected result:
----------------
The above code should print the sendmail error message.

Actual result:
--------------
The above code does prints "good\n"