PHP phpmailer\phpmailer PHPMailer::addAttachment примеры использования

PHP phpmailer\phpmailer PHPMailer::addAttachment - 2 примера найдено. Это лучшие примеры PHP кода для phpmailer\phpmailer\PHPMailer::addAttachment, полученные из open source проектов. Вы можете ставить оценку каждому примеру, чтобы помочь нам улучшить качество примеров.

addAttachment() публичный метод

Returns false if the file could not be found or read.
public addAttachment ( string $path, string $name = '', string $encoding = 'base64', string $type = '', string $disposition = 'attachment' ) : boolean
$path string Path to the attachment.
$name string Overrides the attachment name.
$encoding string File encoding (see $Encoding).
$type string File extension (MIME) type.
$disposition string Disposition to use
Результат boolean
Пример #1
0
 /**
  * @param $file
  * @param null $name
  * @return $this
  */
 public function file($file, $name = null)
 {
     is_null($name) ? $this->mail->addAttachment($file) : $this->mail->addAttachment($file, $name);
     return $this;
 }
Пример #2
0
 /**
  * Add file attachment to the email
  *
  * @param   mixed   $path         Either a string or array of strings [filenames]
  * @param   mixed   $name         Either a string or array of strings [names]
  * @param   mixed   $encoding     The encoding of the attachment
  * @param   mixed   $type         The mime type
  * @param   string  $disposition  The disposition of the attachment
  *
  * @return  JMail|boolean  Returns this object for chaining on success or boolean false on failure.
  *
  * @since   12.2
  * @throws  InvalidArgumentException
  */
 public function addAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream', $disposition = 'attachment')
 {
     // If the file attachments is an array, add each file... otherwise just add the one
     if (isset($path)) {
         // Wrapped in try/catch if PHPMailer is configured to throw exceptions
         try {
             $result = true;
             if (is_array($path)) {
                 if (!empty($name) && count($path) != count($name)) {
                     throw new InvalidArgumentException("The number of attachments must be equal with the number of name");
                 }
                 foreach ($path as $key => $file) {
                     if (!empty($name)) {
                         $result = parent::addAttachment($file, $name[$key], $encoding, $type);
                     } else {
                         $result = parent::addAttachment($file, $name, $encoding, $type);
                     }
                 }
             } else {
                 $result = parent::addAttachment($path, $name, $encoding, $type);
             }
             // Check for boolean false return if exception handling is disabled
             if ($result === false) {
                 return false;
             }
         } catch (phpmailerException $e) {
             // The parent method will have already called the logging callback, just log our deprecated error handling message
             JLog::add(__METHOD__ . '() will not catch phpmailerException objects as of 4.0.', JLog::WARNING, 'deprecated');
             return false;
         }
     }
     return $this;
 }