Framework:sb Email Attachment

From Surebert wiki

Contents

Overview

Used to add email attachment

Methods

__construct

The first argument is the filepath to the file to attach and the second argument is mime_type. Both are optional and can be set afterward.

php code

$attachment = new sb_Email_Attachment($filepath, $mime_type);
//an instance of sb_Email
$email->add_attachment($attachment);

zip

Additionally, attachments can easily be zipped. This sets the mime type to that of a zip file and adds .zip to the name of the attachment.

php code

$attachment->zip();

pgp_encrypt

Or use PGP encryption. This requires a valid .gnupg folder be found in /private/resources and that you pass it a valid key from that for encryption. Mime type changes to application/pgp and adds .pgp to the name of the attachment.

php code

$myAttachment->pgp_encrypt('XXXXE698D01A6C99XXXD67A827XXXXX0B3FE57XX');

properties

Attachments can also easily be set up from blob or string data by setting the contents directly.

example

php code

$attachment = new sb_Email_Attachment();
$attachment->contents = $data_from_db;
$attachment->mime_type = "image/jpeg";
$attachment->name = "picture.jpg";
$email->add_attachment($attachment);

contents

The contents of the attachment. If not reading from a file, you can diretcly poopulate this from a database, e.g. blog data.

php code

$attachment->contents($db);

mime_type

The mime type to use for the attachment. Ths is automatically determined if not supplied, however, you can override it.

php code

$attachment->mime_type = 'image/jpeg';

name

The name to assign to the attachment

php code

$attachment->name = 'flower.jpg';