In your controller, write something like this.
$emial_body = “<table><tr><td>Body of the email</td></tr></table”;
$mail = new Zend_Mail();
$mail->setType(Zend_Mime::MULTIPART_RELATED);
$mail->setBodyHtml($email_body);
$mail->setFrom(‘support@example.com’, ‘Example’);
$mail->addTo(‘user@abc.com’, ‘Username’);
$mail->setSubject(‘Sending email using Zend Framework’);
$mail->send();
Although, this will send email, however it’s not a good approach to create email in your controller as your mail body may contain thousands of words.
The best approach is to create a template, that contain the contents that will act as body of the email. To achieve this, create a file called emailExample.html in your /application/views/scripts/templates/ directory. And write the contents you want to put, those contents will serve as body of the email you are going to send.
$myView = new Zend_View();
$myView->addScriptPath(ROOT_DIR . ‘/application/views/scripts/templates/’);
$html_body = $ myView ->render(emailExample.html’);
$mail = new Zend_Mail();
$mail->setType(Zend_Mime::MULTIPART_RELATED);
$mail->setBodyHtml($html_body);
$mail->setFrom(‘support@example.com’, ‘Example’);
$mail->addTo(‘user@abc.com’, ‘Username’);
$mail->setSubject(‘Sending email using Zend Framework’);
$mail->send();
You can also use file_get_contents() function and then use createAttachment() function.
$fileContents = file_get_contents(‘path/to/file’);
And then call a simple method called createAttachment (), as
$file = $mail->createAttachment($fileContents);
And set the name of the attachment as
$file->filename = “yourfile.doc”;