9.1. 简介

Solar自带了一系列类帮助您建立电子邮件信息,并通过各种不同的传输机制发送它们。这里有一个简单的示例:

<?php
/**
 * first, compose a message
 */

// build a message
$mail = Solar::factory('Solar_Mail_Message');

// from, to, and subject lines
$mail->setFrom('pmjones@example.com')
     ->addTo('bolivar@example.net', 'Bolivar Shagnaasty')
     ->setSubject('An Example Email Message');

// add a "text" body component
$mail->setText("Hello world!");

// add an "html" body component
$mail->setHtml("<p><em>Hello</em> world!</p>");

// add an attachment
$file = '/path/to/image.jpg';
$mime = 'image/jpeg';
$mail->attachFile($file, $mime);

/**
 * now send the message using php mail()
 */

// build a transport
$transport = Solar::factory('Solar_Mail_Transport', array(
    'adapter' => 'Solar_Mail_Transport_Adapter_Phpmail',
));

// send the mail through the transport
$transport->send($mail);
?>