예제 #1
0
 /**
  * Add an attachment to email
  *
  * @param string $filePath
  * @param string $fileName
  * @param string $contentType
  * @param bool   $inline
  *
  * @return void
  */
 public function attachFile($filePath, $fileName = null, $contentType = null, $inline = false)
 {
     if ($this->tokenizationEnabled) {
         // Stash attachment to be processed by the transport
         $this->message->addAttachment($filePath, $fileName, $contentType, $inline);
     } else {
         if (file_exists($filePath) && is_readable($filePath)) {
             try {
                 $attachment = \Swift_Attachment::fromPath($filePath);
                 if (!empty($fileName)) {
                     $attachment->setFilename($fileName);
                 }
                 if (!empty($contentType)) {
                     $attachment->setContentType($contentType);
                 }
                 if ($inline) {
                     $attachment->setDisposition('inline');
                 }
                 $this->message->attach($attachment);
             } catch (\Exception $e) {
                 error_log($e);
             }
         }
     }
 }