[cvs] [Wiki] changed: Doc/Dev/MIMEPackage

Wiki Guest wikiguest at horde.org
Fri Oct 19 13:59:52 UTC 2007


guest [217.78.35.26]  Fri, 19 Oct 2007 06:59:52 -0700

Modified page: http://wiki.horde.org/Doc/Dev/MIMEPackage
New Revision:  3.2
Change log:  add Creating and Sending E-Mail

@@ -31,8 +31,71 @@

 To return the message as a string:
 <code type="php">
 $string = $headers->toString() . "\n\n" . $message->toString();
+</code>
+
+++ Creating and Sending E-Mail with an attachment by using MIME Mail
+<code type="php">
+// Why this? I don't know! perhaps because using the HORDE BASE libs and
there by get the mail_driver
+ at define('AUTH_HANDLER', true);
+
+// Please find your horde base directory, absolute or relative its all up
to you.
+ at define('HORDE_BASE', '/var/www/localhost/htdocs/horde/');
+
+require_once HORDE_BASE . '/lib/base.php';
+require_once HORDE_BASE . '/lib/version.php';
+
+// This are the main library for this example
+require_once 'Horde/MIME.php';
+require_once 'Horde/MIME/Mail.php';
+
+// Various variables for our mail
+$email_to = 'a.guy.called.gerald at localhost';
+$email_from = 'nobody at localhost';
+$subject = 'Simple horde MIME Mail test';
+$file_attachment = '/tmp/some_file.zip';
+$body = "If you can read this and got the attached file, you are on good
track with horde MIME library.";
+
+// New MIME_Mail Object
+$Mail = &new MIME_Mail();
+
+// Set the header date
+$Mail->addHeader('Date', date('r'));
+
+// Set the from address
+$Mail->addHeader('From', $email_from);
+
+// Set the subject of the mail
+$Mail->addHeader('Subject', $subject);
+
+// Set the text message body
+$Mail->setBody($body);
+
+// Add the file as an attachment, set the file name and what kind of mime
it is,
+// Haven't tried this yet, but i assume that the two last parameters can be
left out for automatic detection
+$Mail->addAttachment($file_attachment, 'some_file.zip',
'application/x-zip-compressed');
+
+// Add a recipients
+$Mail->addRecipients($email_to);
+
+// Get the mail driver
+$mail_driver = $conf['mailer']['type'];
+$mail_params = $conf['mailer']['params'];
+if ($mail_driver == 'smtp' && $mail_params['auth'] &&
+    empty($mail_params['username'])) {
+    if (Auth::getAuth()) {
+        $mail_params['username'] = Auth::getAuth();
+        $mail_params['password'] = Auth::getCredential('password');
+    }
+}
+
+// Send the mail
+if (!is_a($sent = $Mail->send($mail_driver, $mail_params), 'PEAR_Error')) {
+    print "E-Mail sent\n";
+} else {
+    print "E-Mail not sent\n";
+}
 </code>

 ++ Parsing a MIME message


More information about the cvs mailing list