123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace Cube\Mail\Transport;
- class Sendmail extends AbstractTransport
- {
-
- protected $_path = '/usr/sbin/sendmail';
-
- public function __construct(array $options = null)
- {
- parent::__construct($options);
- }
-
- public function getPath()
- {
- return $this->_path;
- }
-
- public function setPath($path)
- {
- $this->_path = $path;
- return $this;
- }
-
- public function send()
- {
- $result = false;
- $mail = $this->getMail();
- $mailHeader = $mail->createHeader();
- $mailBody = $mail->getBody();
- $from = $mail->getFrom();
- $sendmail = sprintf("%s -oi -f%s -t", escapeshellcmd($this->_path), escapeshellarg($from['address']));
- foreach ($mail->getTo() as $to) {
- if (!@$mail = popen($sendmail, 'w')) {
- throw new \RuntimeException(sprintf(
- "Could not execute sendmail program, path given: '%s'.", $this->_path));
- }
- fputs($mail, "To: " . $to['address'] . "\n");
- fputs($mail, $mailHeader . "\n");
- fputs($mail, $mailBody . "\n");
- $result = pclose($mail);
- }
- $result = ($result == 0) ? true : false;
- return $result;
- }
- }
|