Skip to content

Commit b1b82fe

Browse files
author
Oleksandr Iegorov
committed
Merge branch 'MAGETWO-95137' of github.com:magento-tango/magento2ce into PR-1911
2 parents 2f7b342 + caab8f7 commit b1b82fe

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

app/code/Magento/Email/Model/Transport.php

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ class Transport implements TransportInterface
3131
*/
3232
const XML_PATH_SENDING_RETURN_PATH_EMAIL = 'system/smtp/return_path_email';
3333

34+
/**
35+
* Whether return path should be set or no.
36+
*
37+
* Possible values are:
38+
* 0 - no
39+
* 1 - yes (set value as FROM address)
40+
* 2 - use custom value
41+
*
42+
* @var int
43+
*/
44+
private $isSetReturnPath;
45+
46+
/**
47+
* @var string|null
48+
*/
49+
private $returnPathValue;
50+
3451
/**
3552
* @var Sendmail
3653
*/
@@ -51,25 +68,15 @@ public function __construct(
5168
ScopeConfigInterface $scopeConfig,
5269
$parameters = null
5370
) {
54-
/* configuration of whether return path should be set or no. Possible values are:
55-
* 0 - no
56-
* 1 - yes (set value as FROM address)
57-
* 2 - use custom value
58-
* @see Magento\Config\Model\Config\Source\Yesnocustom
59-
*/
60-
$isSetReturnPath = $scopeConfig->getValue(
71+
$this->isSetReturnPath = (int) $scopeConfig->getValue(
6172
self::XML_PATH_SENDING_SET_RETURN_PATH,
6273
ScopeInterface::SCOPE_STORE
6374
);
64-
$returnPathValue = $scopeConfig->getValue(
75+
$this->returnPathValue = $scopeConfig->getValue(
6576
self::XML_PATH_SENDING_RETURN_PATH_EMAIL,
6677
ScopeInterface::SCOPE_STORE
6778
);
6879

69-
if ($isSetReturnPath == '2' && $returnPathValue !== null) {
70-
$parameters .= ' -f' . \escapeshellarg($returnPathValue);
71-
}
72-
7380
$this->zendTransport = new Sendmail($parameters);
7481
$this->message = $message;
7582
}
@@ -80,9 +87,16 @@ public function __construct(
8087
public function sendMessage()
8188
{
8289
try {
83-
$this->zendTransport->send(
84-
Message::fromString($this->message->getRawMessage())
85-
);
90+
$zendMessage = Message::fromString($this->message->getRawMessage());
91+
if (2 === $this->isSetReturnPath && $this->returnPathValue) {
92+
$zendMessage->setSender($this->returnPathValue);
93+
} elseif (1 === $this->isSetReturnPath && $zendMessage->getFrom()->count()) {
94+
$fromAddressList = $zendMessage->getFrom();
95+
$fromAddressList->rewind();
96+
$zendMessage->setSender($fromAddressList->current()->getEmail());
97+
}
98+
99+
$this->zendTransport->send($zendMessage);
86100
} catch (\Exception $e) {
87101
throw new MailException(new Phrase($e->getMessage()), $e);
88102
}

0 commit comments

Comments
 (0)