Skip to content

Commit

Permalink
Update source + additional header
Browse files Browse the repository at this point in the history
  • Loading branch information
snipworks committed Mar 5, 2019
1 parent 8309a7d commit 9e754b4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
}
},
"require": {
"php": ">=5.3"
"php": ">=5.3",
"ext-openssl": "*"
}
}
29 changes: 18 additions & 11 deletions src/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ class Email
protected $charset = 'utf-8';

/** @var array $headers */
protected $headers = array(
'MIME-Version' => '1.0',
);
protected $headers = array();

/**
* Class constructor
Expand All @@ -103,6 +101,8 @@ public function __construct($server, $port = 25, $connectionTimeout = 30, $respo
$this->connectionTimeout = $connectionTimeout;
$this->responseTimeout = $responseTimeout;
$this->hostname = empty($hostname) ? gethostname() : $hostname;
$this->headers['X-Mailer'] = 'PHP/' . phpversion();
$this->headers['MIME-Version'] = '1.0';
}

/**
Expand Down Expand Up @@ -293,8 +293,14 @@ public function getLogs()
*/
public function send()
{
$this->socket = fsockopen($this->getServer(), $this->port, $error_number, $error_string,
$this->connectionTimeout);
$this->socket = fsockopen(
$this->getServer(),
$this->port,
$errorNumber,
$errorMessage,
$this->connectionTimeout
);

if (empty($this->socket)) {
return false;
}
Expand All @@ -321,7 +327,13 @@ public function send()
$this->headers['Date'] = date('r');
$this->headers['Subject'] = $this->subject;
$this->headers['From'] = $this->formatAddress($this->from);
$this->headers['Return-Path'] = $this->formatAddress($this->from);
$this->headers['To'] = $this->formatAddressList($this->to);

if (!empty($this->replyTo)) {
$this->headers['Reply-To'] = $this->formatAddressList($this->replyTo);
}

if (!empty($this->cc)) {
$this->headers['Cc'] = $this->formatAddressList($this->cc);
}
Expand All @@ -330,12 +342,6 @@ public function send()
$this->headers['Bcc'] = $this->formatAddressList($this->bcc);
}

if (!empty($this->replyTo)) {
$this->headers['Reply-To'] = $this->formatAddressList($this->replyTo);
}

$this->logs['DATA'][1] = $this->sendCommand('DATA');

$boundary = md5(uniqid(microtime(true), true));
$this->headers['Content-Type'] = 'multipart/mixed; boundary="mixed-' . $boundary . '"';

Expand Down Expand Up @@ -380,6 +386,7 @@ public function send()

$this->logs['MESSAGE'] = $message;
$this->logs['HEADERS'] = $headers;
$this->logs['DATA'][1] = $this->sendCommand('DATA');
$this->logs['DATA'][2] = $this->sendCommand($headers . self::CRLF . $message . self::CRLF . '.');
$this->logs['QUIT'] = $this->sendCommand('QUIT');
fclose($this->socket);
Expand Down

0 comments on commit 9e754b4

Please sign in to comment.