Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Transport.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Email\Model;
7 
14 use Zend\Mail\Message;
15 use Zend\Mail\Transport\Sendmail;
16 
21 class Transport implements TransportInterface
22 {
27  const XML_PATH_SENDING_SET_RETURN_PATH = 'system/smtp/set_return_path';
28 
32  const XML_PATH_SENDING_RETURN_PATH_EMAIL = 'system/smtp/return_path_email';
33 
37  private $zendTransport;
38 
42  private $message;
43 
49  public function __construct(
50  MessageInterface $message,
51  ScopeConfigInterface $scopeConfig,
52  $parameters = null
53  ) {
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(
61  self::XML_PATH_SENDING_SET_RETURN_PATH,
63  );
64  $returnPathValue = $scopeConfig->getValue(
65  self::XML_PATH_SENDING_RETURN_PATH_EMAIL,
67  );
68 
69  if ($isSetReturnPath == '2' && $returnPathValue !== null) {
70  $parameters .= ' -f' . \escapeshellarg($returnPathValue);
71  }
72 
73  $this->zendTransport = new Sendmail($parameters);
74  $this->message = $message;
75  }
76 
80  public function sendMessage()
81  {
82  try {
83  $this->zendTransport->send(
84  Message::fromString($this->message->getRawMessage())
85  );
86  } catch (\Exception $e) {
87  throw new MailException(new Phrase($e->getMessage()), $e);
88  }
89  }
90 
94  public function getMessage()
95  {
96  return $this->message;
97  }
98 }
$message
__construct(MessageInterface $message, ScopeConfigInterface $scopeConfig, $parameters=null)
Definition: Transport.php:49
getValue($path, $scopeType=ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode=null)