Skip to content

Commit

Permalink
Merge pull request #617 from rmayhue/enhancement/smtp_attachment_alias
Browse files Browse the repository at this point in the history
Add alias filename for email attachemnt
  • Loading branch information
bcosca committed Aug 8, 2014
2 parents 9afce1f + 27fb768 commit 27ed718
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/smtp.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,13 @@ protected function dialog($cmd=NULL,$log=TRUE) {
* Add e-mail attachment
* @return NULL
* @param $file
* @param $alias
**/
function attach($file) {
function attach($file,$alias=NULL) {
if (!is_file($file))
user_error(sprintf(self::E_Attach,$file));
if (is_string($alias))
$file=array($alias=>$file);
$this->attachments[]=$file;
}

Expand Down Expand Up @@ -217,11 +220,19 @@ function send($message,$log=TRUE) {
$out.=$eol;
$out.=$message.$eol;
foreach ($this->attachments as $attachment) {
if (is_array($attachment)) {
list($alias, $file) = each($attachment);
$filename = $alias;
$attachment = $file;
}
else {
$filename = basename($attachment);
}
$out.='--'.$hash.$eol;
$out.='Content-Type: application/octet-stream'.$eol;
$out.='Content-Transfer-Encoding: base64'.$eol;
$out.='Content-Disposition: attachment; '.
'filename="'.basename($attachment).'"'.$eol;
'filename="'.$filename.'"'.$eol;
$out.=$eol;
$out.=chunk_split(
base64_encode(file_get_contents($attachment))).$eol;
Expand Down

0 comments on commit 27ed718

Please sign in to comment.