Send e-mail with attachments in Zend Framework

Description:

Send an e-mail containing attachments with Zend Framework.

Solution:

Zend offers an easier solution for sending e-mail with attachements than plain PhP. 

Basically the object has to be instantiated and then just configuring the parameters.

Example:

$email_body = “<div>Body text here</div>”;

$mail = new Zend_Mail();
$mail->setType(Zend_Mime::MULTIPART_RELATED);
$mail->setBodyHtml($email_body);
$mail->setFrom(‘from_me@mail.com’, ‘Sender name’);
$mail->addTo(‘to_you@mail.com’, ‘Receiver name’);
$mail->setSubject(‘E-mail with Zend, and attachments’);

$attachment1 = file_get_contents(‘list.zip’);
$file = $mail->createAttachment($attachment1);

$mail->send();

Advertisements

About admin

Just another php developer trying to give something back to the community.
This entry was posted in PhP, Tools and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s