Send Html Mails with Zend_Mail

Zend_Mail
Typically you’d never like to send a non-html formatted mail from your web system. It’s ugly and it’s difficult to read. Instead of sending pure text, you’d like to add some images and styles. The way you can do it with Zend_Mail is simple enough. Replace the setBody method with setBodyHtml. Isn’t that natural?

// before
$mail = new Zend_Mail('utf-8');
$mail->setFrom('sender@example.com', 'Sender Name');
$mail->setBody('message in Html');
$mail->addTo('recipient@example.com', 'Recepient Name');
$mail->setSubject('Subject');
$mail->send();
// after
$mail = new Zend_Mail('utf-8');
$mail->setFrom('sender@example.com', 'Sender Name');
$mail->setBodyHtml('message in Html');
$mail->addTo('recipient@example.com', 'Recepient Name');
$mail->setSubject('Subject');
$mail->send();

Related posts:

  1. Send Mail with Zend Framework
  2. Zend_Mail with GMail
  3. Send Authenticated POST Request with Zend_Http_Client
This entry was posted in micro tutorial, PHP, zend framework and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">