Skip to content

Commit

Permalink
Add mechanism for allowing sending messages with an empty body [via S…
Browse files Browse the repository at this point in the history
  • Loading branch information
Synchro committed Mar 21, 2013
1 parent 230e369 commit 5d64a6e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
12 changes: 9 additions & 3 deletions class.phpmailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,13 @@ class PHPMailer {
*/
public $SingleToArray = array();

/**
/**
* Should we allow sending messages with empty body?
* @var bool
*/
public $AllowEmpty = false;

/**
* Provides the ability to change the generic line ending
* NOTE: The default remains '\n'. We force CRLF where we KNOW
* it must be used via self::CRLF
Expand Down Expand Up @@ -789,8 +795,8 @@ public function PreSend() {

$this->error_count = 0; // reset errors
$this->SetMessageType();
//Refuse to send an empty message
if (empty($this->Body)) {
//Refuse to send an empty message unless we are specifically allowing it
if (!$this->AllowEmpty and empty($this->Body)) {
throw new phpmailerException($this->Lang('empty_message'), self::STOP_CRITICAL);
}

Expand Down
18 changes: 16 additions & 2 deletions test/phpmailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -936,11 +936,25 @@ function test_MailSend()
}
$this->Mail->Body = 'Sending via mail()';
$this->BuildBody();
$subject = $this->Mail->Subject;

$this->Mail->Subject = $subject . ': mail()';
$this->Mail->Subject = $this->Mail->Subject . ': mail()';
$this->Mail->IsMail();
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
}

/**
* Test sending an empty body
*/
function test_Empty_Body()
{
$this->BuildBody();
$this->Mail->Body = '';
$this->Mail->Subject = $this->Mail->Subject . ': Empty Body';
$this->Mail->IsMail();
$this->Mail->AllowEmpty = true;
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
$this->Mail->AllowEmpty = false;
$this->assertFalse($this->Mail->Send(), $this->Mail->ErrorInfo);
}

/**
Expand Down

0 comments on commit 5d64a6e

Please sign in to comment.