Skip to content

Commit 5cb58e8

Browse files
committed
Implemented methods to configure "from".
1 parent 8f5049e commit 5cb58e8

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

lib/Cake/Network/CakeEmail.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,30 @@ public function __construct() {
199199
}
200200
}
201201

202+
/**
203+
* Set From
204+
*
205+
* @param string $email
206+
* @param string $name
207+
* @return void
208+
*/
209+
public function setFrom($email, $name = null) {
210+
if ($name !== null) {
211+
$this->_from = array($email => $name);
212+
} else {
213+
$this->_from = array($email => $email);
214+
}
215+
}
216+
217+
/**
218+
* Get the From information
219+
*
220+
* @return array Key is email, Value is name. If Key is equal of Value, the name is not specified
221+
*/
222+
public function getFrom() {
223+
return $this->_from;
224+
}
225+
202226
/**
203227
* Sets headers for the message
204228
*

lib/Cake/tests/Case/Network/CakeEmailTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,33 @@
2525
*/
2626
class CakeEmailTest extends CakeTestCase {
2727

28+
/**
29+
* setUp
30+
*
31+
* @return void
32+
*/
33+
public function setUp() {
34+
parent::setUp();
35+
$this->CakeEmail = new CakeEmail();
36+
}
37+
38+
/**
39+
* testFrom method
40+
*
41+
* @return void
42+
*/
43+
public function testFrom() {
44+
$this->assertIdentical($this->CakeEmail->getFrom(), array());
45+
46+
$this->CakeEmail->setFrom('cake@cakephp.org');
47+
$expected = array('cake@cakephp.org' => 'cake@cakephp.org');
48+
$this->assertIdentical($this->CakeEmail->getFrom(), $expected);
49+
50+
$this->CakeEmail->setFrom('cake@cakephp.org', 'CakePHP');
51+
$expected = array('cake@cakephp.org' => 'CakePHP');
52+
$this->assertIdentical($this->CakeEmail->getFrom(), $expected);
53+
}
54+
2855
/**
2956
* testHeaders method
3057
*

0 commit comments

Comments
 (0)