Chapter 20. Zend_Mail

Table of Contents

20.1. Introduction
20.2. Sending via SMTP
20.3. Posielanie viacerých e-mailov cez jedno SMTP spojenie
20.4. Using Different Transports
20.5. HTML e-mail
20.6. Attachments
20.7. Pridávanie príjemcov
20.8. Nastavenie hranice MIME
20.9. Iné e-mail hlavičky
20.10. Znakové sady
20.11. Kódovanie
20.12. SMTP Authentication
20.13. Securing SMTP Transport
20.14. Reading Mail Messages
20.14.1. Simple example using Pop3
20.14.2. Opening a local storage
20.14.3. Opening a remote storage
20.14.4. Fetching messages and simple methods
20.14.5. Working with messages
20.14.6. Checking for flags
20.14.7. Using folders
20.14.8. Advanced Use

20.1. Introduction

Zend_Mail provides generalized functionality to compose and send both text and MIME-compliant multipart e-mail messages. Mail can be sent with Zend_Mail via the php built-in mail() function or via direct SMTP connection.

Example 20.1. Simple E-Mail with Zend_Mail

A simple e-mail consists of some recipients, a subject, a body and a sender. To send such a mail using the PHP mail() function, do the following:

<?php
require_once 'Zend/Mail.php';
$mail = new Zend_Mail();
$mail->setBodyText('This is the text of the mail.');
$mail->setFrom('somebody@example.com', 'Some Sender');
$mail->addTo('somebody_else@example.com', 'Some Recipient');
$mail->setSubject('TestSubject');
$mail->send();
?>   
[Note] Minimum definitions

In order to send an e-mail with Zend_Mail you have to specify at least one recipient, a sender (e.g., with setFrom()), and a message body (text and/or HTML).

For most mail attributes there are "get" methods to read the information stored in the mail object. For further details, please refer to the API documentation. A special one is getRecipients(). It returns an array with all recipient e-mail addresses that were added prior to the method call.

For security reasons, Zend_Mail filters all header fields to prevent header injection with newline (\n) characters.