Class for handling email sending

Gracefully degrades in functionality if certain PEAR libraries are not available.

Sending Mails

Currently, the engine will send the emails through an autodetected backend, which can be either Mail_smtp, Mail_sendmail or PHP's mail() function (in that order).

Example usage code

$mail = new org_openpsa_mail();

$mail->from = '';
$mail->subject = $this->_config->get('mail_from');
$mail->body = $this->_config->get('mail_body');
$mail->to = $this->_person->email;

if (!$mail->send())
    debug_add("Email could not be sent: " . $mail->get_error_string(), MIDCOM_LOG_WARN);
package org.openpsa.mail


__construct ($backend, $backend_params)




__get ($name)

Make it possible to get header values via $mail->to and the like



__set ($name, $value)

Make it possible to set header values via $mail->to and the like




can_attach ()

Returns true/false depending on whether we can send attachments

embed_images ($obj)

Find embeds from source HTML, intentionally does NOT use $this->html_body

@param midcom_core_dbaobject $object Optional DBA object from which attachments can be read



get_error_message ()

Get errormessage from mail class

Handles also the PEAR errors from libraries used.

html2text ($html)

Tries to convert HTML to plaintext



send ()

Sends the email

_exists_in_embeds ($input, $embeds)

Whether given file definition is already in embeds




_get_mimetype ($content, $name)

Determine correct mimetype for file we have only content (and perhaps filename) for.




_html_get_embeds_loop ($obj, $html, $search, $embeds, $type)







_prepare_message ()

Prepares message for sending

Calls MIME etc encodings as necessary.



boolean $allow_only_html

Allow to send only HTML body

array $attachments

Primary keys are int, secondary keys for decoded array are:

'name' (filename) 'content' (file contents) 'mimetype' Array for encoding may instead of 'content' have 'file' which is path to the file to be attached


string $body

Text body

string $encoding

Character encoding in which the texts etc are

array $headers

key is header name, value is header data

string $html_body

HTML body (of MIME/multipart message)

array $parameters

The parameters to use for the Mail template.

\org_openpsa_mail_backend $_backend

The backend object

array $_embeds

Like attachments but used for inline images.

This is dynamically filled from html_body if embed_images is called