From 2fe4ff02f2186c83f9f03922bc34b8cb884e260c Mon Sep 17 00:00:00 2001 From: Benjamin Milde Date: Sat, 1 Oct 2016 20:35:09 +0200 Subject: [PATCH] Allow for alternative names to be supplied --- wire/core/WireMail.php | 8 ++++---- wire/core/WireMailInterface.php | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/wire/core/WireMail.php b/wire/core/WireMail.php index 935d0bc7..a92892ae 100644 --- a/wire/core/WireMail.php +++ b/wire/core/WireMail.php @@ -328,11 +328,12 @@ class WireMail extends WireData implements WireMailInterface { * @return this * */ - public function attachment($value) { + public function attachment($value, $filename = '') { if(is_null($value)) { $this->mail['attachments'] = array(); } else if(is_file($value)) { - $this->mail['attachments'][] = $value; + $filename = $filename ?: basename($value); + $this->mail['attachments'][$filename] = $value; } return $this; } @@ -389,10 +390,9 @@ class WireMail extends WireData implements WireMailInterface { } // Attachments - foreach ($this->attachments as $file) { + foreach ($this->attachments as $filename => $file) { $content = file_get_contents($file); $content = chunk_split(base64_encode($content)); - $filename = basename($file); $body .= "--$boundary\r\n" . "Content-Type: application/octet-stream; name=\"$filename\"\r\n" . diff --git a/wire/core/WireMailInterface.php b/wire/core/WireMailInterface.php index 328e10d1..937ff269 100644 --- a/wire/core/WireMailInterface.php +++ b/wire/core/WireMailInterface.php @@ -94,9 +94,10 @@ interface WireMailInterface { * * * @param string $value + * @param string $filename * @return this * - public function attachment($value); + public function attachment($value, $filename = ''); */ /**