mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Added support to sender email. Fixes #13.
This commit is contained in:
parent
baba9fd270
commit
e0b4623065
6 changed files with 59 additions and 3 deletions
|
@ -59,6 +59,7 @@ class EmailConfig {
|
|||
|
||||
public $fast = array(
|
||||
'from' => 'you@localhost',
|
||||
'sender' => null,
|
||||
'to' => null,
|
||||
'cc' => null,
|
||||
'bcc' => null,
|
||||
|
|
|
@ -59,6 +59,7 @@ class EmailConfig {
|
|||
|
||||
public $fast = array(
|
||||
'from' => 'you@localhost',
|
||||
'sender' => null,
|
||||
'to' => null,
|
||||
'cc' => null,
|
||||
'bcc' => null,
|
||||
|
|
|
@ -80,6 +80,13 @@ class CakeEmail {
|
|||
*/
|
||||
protected $_from = array();
|
||||
|
||||
/**
|
||||
* The sender email
|
||||
*
|
||||
* @var array();
|
||||
*/
|
||||
protected $_sender = array();
|
||||
|
||||
/**
|
||||
* The email the recipient will reply to
|
||||
*
|
||||
|
@ -279,6 +286,21 @@ class CakeEmail {
|
|||
return $this->_setEmailSingle('_from', $email, $name, __d('cake', 'From requires only 1 email address.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sender
|
||||
*
|
||||
* @param mixed $email
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
* @thrown SocketException
|
||||
*/
|
||||
public function sender($email = null, $name = null) {
|
||||
if ($email === null) {
|
||||
return $this->_sender;
|
||||
}
|
||||
return $this->_setEmailSingle('_sender', $email, $name, __d('cake', 'Sender requires only 1 email address.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reply-To
|
||||
*
|
||||
|
@ -550,6 +572,7 @@ class CakeEmail {
|
|||
public function getHeaders($include = array()) {
|
||||
$defaults = array(
|
||||
'from' => false,
|
||||
'sender' => false,
|
||||
'replyTo' => false,
|
||||
'readReceipt' => false,
|
||||
'returnPath' => false,
|
||||
|
@ -573,6 +596,13 @@ class CakeEmail {
|
|||
$headers[$header] = current($this->_formatAddress($this->{$var}));
|
||||
}
|
||||
}
|
||||
if ($include['sender']) {
|
||||
if (key($this->_sender) === key($this->_from)) {
|
||||
$headers['Sender'] = '';
|
||||
} else {
|
||||
$headers['Sender'] = current($this->_formatAddress($this->_sender));
|
||||
}
|
||||
}
|
||||
|
||||
foreach (array('to', 'cc', 'bcc') as $var) {
|
||||
if ($include[$var]) {
|
||||
|
@ -973,7 +1003,7 @@ class CakeEmail {
|
|||
*/
|
||||
protected static function _applyConfig(CakeEmail $obj, $config) {
|
||||
$simpleMethods = array(
|
||||
'from', 'to', 'replyTo', 'readReceipt', 'returnPath', 'cc', 'bcc',
|
||||
'from', 'sender', 'to', 'replyTo', 'readReceipt', 'returnPath', 'cc', 'bcc',
|
||||
'messageId', 'subject', 'viewRender', 'viewVars', 'attachments',
|
||||
'transport', 'emailFormat'
|
||||
);
|
||||
|
@ -1007,6 +1037,7 @@ class CakeEmail {
|
|||
public function reset() {
|
||||
$this->_to = array();
|
||||
$this->_from = array();
|
||||
$this->_sender = array();
|
||||
$this->_replyTo = array();
|
||||
$this->_readReceipt = array();
|
||||
$this->_returnPath = array();
|
||||
|
|
|
@ -35,7 +35,7 @@ class MailTransport extends AbstractTransport {
|
|||
if (isset($this->_config['eol'])) {
|
||||
$eol = $this->_config['eol'];
|
||||
}
|
||||
$headers = $email->getHeaders(array_fill_keys(array('from', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc'), true));
|
||||
$headers = $email->getHeaders(array_fill_keys(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc'), true));
|
||||
$to = $headers['To'];
|
||||
unset($headers['To']);
|
||||
$header = $this->_headersToString($headers, $eol);
|
||||
|
|
|
@ -158,7 +158,7 @@ class SmtpTransport extends AbstractTransport {
|
|||
protected function _sendData() {
|
||||
$this->_smtpSend('DATA', '354');
|
||||
|
||||
$headers = $this->_cakeEmail->getHeaders(array_fill_keys(array('from', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject'), true));
|
||||
$headers = $this->_cakeEmail->getHeaders(array_fill_keys(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject'), true));
|
||||
$headers = $this->_headersToString($headers);
|
||||
$message = implode("\r\n", $this->_cakeEmail->message());
|
||||
pr($headers . "\r\n\r\n" . $message . "\r\n\r\n\r\n.");
|
||||
|
|
|
@ -174,6 +174,29 @@ class CakeEmailTest extends CakeTestCase {
|
|||
$this->assertIdentical($this->CakeEmail, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testSender method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSender() {
|
||||
$this->CakeEmail->reset();
|
||||
$this->assertIdentical($this->CakeEmail->sender(), array());
|
||||
|
||||
$this->CakeEmail->sender('cake@cakephp.org', 'Name');
|
||||
$expected = array('cake@cakephp.org' => 'Name');
|
||||
$this->assertIdentical($this->CakeEmail->sender(), $expected);
|
||||
|
||||
$headers = $this->CakeEmail->getHeaders(array('from' => true, 'sender' => true));
|
||||
$this->assertIdentical($headers['From'], false);
|
||||
$this->assertIdentical($headers['Sender'], 'Name <cake@cakephp.org>');
|
||||
|
||||
$this->CakeEmail->from('cake@cakephp.org', 'CakePHP');
|
||||
$headers = $this->CakeEmail->getHeaders(array('from' => true, 'sender' => true));
|
||||
$this->assertIdentical($headers['From'], 'CakePHP <cake@cakephp.org>');
|
||||
$this->assertIdentical($headers['Sender'], '');
|
||||
}
|
||||
|
||||
/**
|
||||
* testTo method
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue