PHPMailer\PHPMailer\PHPMailer::addAttachment PHP Method

addAttachment() public method

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
return boolean
    public function addAttachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment')
    {
        try {
            if (!@is_file($path)) {
                throw new Exception($this->lang('file_access') . $path, self::STOP_CONTINUE);
            }
            // If a MIME type is not specified, try to work it out from the file name
            if ('' == $type) {
                $type = static::filenameToType($path);
            }
            $filename = basename($path);
            if ('' == $name) {
                $name = $filename;
            }
            $this->attachment[] = [0 => $path, 1 => $filename, 2 => $name, 3 => $encoding, 4 => $type, 5 => false, 6 => $disposition, 7 => 0];
        } catch (Exception $exc) {
            $this->setError($exc->getMessage());
            $this->edebug($exc->getMessage());
            if ($this->exceptions) {
                throw $exc;
            }
            return false;
        }
        return true;
    }

Usage Example

Ejemplo n.º 1
4
 /**
  * @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;
 }
All Usage Examples Of PHPMailer\PHPMailer\PHPMailer::addAttachment