PHPMailer::addStringAttachment PHP Method

addStringAttachment() public method

This method can be used to attach ascii or binary data, such as a BLOB record from a database.
public addStringAttachment ( string $string, string $filename, string $encoding = 'base64', string $type = '', string $disposition = 'attachment' ) : void
$string string String attachment data.
$filename string Name of the attachment.
$encoding string File encoding (see $Encoding).
$type string File extension (MIME) type.
$disposition string Disposition to use
return void
    public function addStringAttachment($string, $filename, $encoding = 'base64', $type = '', $disposition = 'attachment')
    {
        // If a MIME type is not specified, try to work it out from the file name
        if ($type == '') {
            $type = self::filenameToType($filename);
        }
        // Append to $attachment array
        $this->attachment[] = array(0 => $string, 1 => $filename, 2 => basename($filename), 3 => $encoding, 4 => $type, 5 => true, 6 => $disposition, 7 => 0);
    }

Usage Example

Example #1
0
 /**
  * Simple plain string attachment test.
  */
 public function testPlainStringAttachment()
 {
     $this->Mail->Body = 'Here is the text body';
     $this->Mail->Subject .= ': Plain + StringAttachment';
     $sAttachment = 'These characters are the content of the ' . "string attachment.\nThis might be taken from a " . 'database or some other such thing. ';
     $this->Mail->addStringAttachment($sAttachment, 'string_attach.txt');
     $this->buildBody();
     $this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
 }
All Usage Examples Of PHPMailer::addStringAttachment