Skip to content

Commit 9ca2bb9

Browse files
author
epriestley
committedMar 30, 2013
Use ExecFuture to raise sendmail error codes out of PHPMailer
Summary: Ref T2843. We currently drop any stdout/stderr emitted by sendmail. Instead, use `ExecFuture` so we'll throw an exception with debugging information preserved. @tido, can you apply this and restart the daemons? Test Plan: Rests on @tido Reviewers: tido, btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2843 Differential Revision: https://secure.phabricator.com/D5464
1 parent a2ebfef commit 9ca2bb9

File tree

2 files changed

+18
-50
lines changed

2 files changed

+18
-50
lines changed
 

‎externals/phpmailer/class.phpmailer-lite.php

+9-25
Original file line numberDiff line numberDiff line change
@@ -532,36 +532,20 @@ protected function SendmailSend($header, $body) {
532532
} else {
533533
$sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
534534
}
535+
535536
if ($this->SingleTo === true) {
536537
foreach ($this->SingleToArray as $key => $val) {
537-
if(!@$mail = popen($sendmail, 'w')) {
538-
throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
539-
}
540-
fputs($mail, "To: " . $val . "\n");
541-
fputs($mail, $header);
542-
fputs($mail, $body);
543-
$result = pclose($mail);
544-
// implement call back function if it exists
545-
$isSent = ($result == 0) ? 1 : 0;
546-
$this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
547-
if($result != 0) {
548-
throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
549-
}
538+
$mail = new ExecFuture('%C', $sendmail);
539+
$mail->write("To: {$val}\n", true);
540+
$mail->write($header.$body);
541+
$mail->resolvex();
550542
}
551543
} else {
552-
if(!@$mail = popen($sendmail, 'w')) {
553-
throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
554-
}
555-
fputs($mail, $header);
556-
fputs($mail, $body);
557-
$result = pclose($mail);
558-
// implement call back function if it exists
559-
$isSent = ($result == 0) ? 1 : 0;
560-
$this->doCallback($isSent,$this->to,$this->cc,$this->bcc,$this->Subject,$body);
561-
if($result != 0) {
562-
throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
563-
}
544+
$mail = new ExecFuture('%C', $sendmail);
545+
$mail->write($header.$body);
546+
$mail->resolvex();
564547
}
548+
565549
return true;
566550
}
567551

‎externals/phpmailer/class.phpmailer.php

+9-25
Original file line numberDiff line numberDiff line change
@@ -601,36 +601,20 @@ protected function SendmailSend($header, $body) {
601601
} else {
602602
$sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
603603
}
604+
604605
if ($this->SingleTo === true) {
605606
foreach ($this->SingleToArray as $key => $val) {
606-
if(!@$mail = popen($sendmail, 'w')) {
607-
throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
608-
}
609-
fputs($mail, "To: " . $val . "\n");
610-
fputs($mail, $header);
611-
fputs($mail, $body);
612-
$result = pclose($mail);
613-
// implement call back function if it exists
614-
$isSent = ($result == 0) ? 1 : 0;
615-
$this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
616-
if($result != 0) {
617-
throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
618-
}
607+
$mail = new ExecFuture('%C', $sendmail);
608+
$mail->write("To: {$val}\n", true);
609+
$mail->write($header.$body);
610+
$mail->resolvex();
619611
}
620612
} else {
621-
if(!@$mail = popen($sendmail, 'w')) {
622-
throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
623-
}
624-
fputs($mail, $header);
625-
fputs($mail, $body);
626-
$result = pclose($mail);
627-
// implement call back function if it exists
628-
$isSent = ($result == 0) ? 1 : 0;
629-
$this->doCallback($isSent,$this->to,$this->cc,$this->bcc,$this->Subject,$body);
630-
if($result != 0) {
631-
throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
632-
}
613+
$mail = new ExecFuture('%C', $sendmail);
614+
$mail->write($header.$body);
615+
$mail->resolvex();
633616
}
617+
634618
return true;
635619
}
636620

0 commit comments

Comments
 (0)
Failed to load comments.