Tag: Email Attachment in Zend

Sending Email with attachment in Zend Framework

Note : You must remember add ( <form enctype=”multipart/form-data” > ) in form tag.

<?php
$message=”<table><tr><td>Body of the email</td></tr></table>” ;
$subject = ‘Attachement Email’;

$config = array(‘auth’ => ‘login’,
‘username’ => ‘Email Id’, 
‘password’ => ‘xxxxxxx’); 

// SMTP must be change according to Mail Server

$transport = new Zend_Mail_Transport_Smtp(‘mail.gmail.com’, $config);

$mail = new Zend_Mail();

$mail->setType(Zend_Mime::MULTIPART_RELATED);
$mail->setBodyText($message);
$mail->setBodyHtml($message);
$mail->setFrom(”info@gmail.com.”,”userName”);
$mail->addTo(’email@gmail.com’);
$mail->setSubject($subject);
$fileContents = file_get_contents($_FILES[‘Attachment’][‘tmp_name’]); // To Be Required Attachement File name
$at=$mail->createAttachment($fileContents);
$at->filename = $_FILES[‘Attachment’][‘name’]; // To Be Required Attachement File name

$mail->send($transport);