@@ -31,6 +31,23 @@ class Transport implements TransportInterface
31
31
*/
32
32
const XML_PATH_SENDING_RETURN_PATH_EMAIL = 'system/smtp/return_path_email ' ;
33
33
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
+
34
51
/**
35
52
* @var Sendmail
36
53
*/
@@ -51,25 +68,15 @@ public function __construct(
51
68
ScopeConfigInterface $ scopeConfig ,
52
69
$ parameters = null
53
70
) {
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 (
61
72
self ::XML_PATH_SENDING_SET_RETURN_PATH ,
62
73
ScopeInterface::SCOPE_STORE
63
74
);
64
- $ returnPathValue = $ scopeConfig ->getValue (
75
+ $ this -> returnPathValue = $ scopeConfig ->getValue (
65
76
self ::XML_PATH_SENDING_RETURN_PATH_EMAIL ,
66
77
ScopeInterface::SCOPE_STORE
67
78
);
68
79
69
- if ($ isSetReturnPath == '2 ' && $ returnPathValue !== null ) {
70
- $ parameters .= ' -f ' . \escapeshellarg ($ returnPathValue );
71
- }
72
-
73
80
$ this ->zendTransport = new Sendmail ($ parameters );
74
81
$ this ->message = $ message ;
75
82
}
@@ -80,9 +87,16 @@ public function __construct(
80
87
public function sendMessage ()
81
88
{
82
89
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 );
86
100
} catch (\Exception $ e ) {
87
101
throw new MailException (new Phrase ($ e ->getMessage ()), $ e );
88
102
}
0 commit comments