Computing Magazine

Send E-mail with Attachments in Zend Framework

Posted on the 31 August 2012 by Akahgy

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(‘[email protected]’, ‘Sender name’);
$mail->addTo(‘[email protected]’, ‘Receiver name’);
$mail->setSubject(‘E-mail with Zend, and attachments’);

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

$mail->send();


Back to Featured Articles on Logo Paperblog