Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minimizing Zend Framework to Zend_Mail? [duplicate]

Possible Duplicate:
Use Zend Framework components without the actual framework?

I just need the Zend_Mail functions of the Zend Framework, but the whole framework is about 300MB in size. Is there a way to cut it down to just the basics and Zend_Mail to save up some disk space?

like image 418
Big-Blue Avatar asked Dec 06 '22 16:12

Big-Blue


1 Answers

Yes, I have used Zend_Mail with SMTP standalone before, here are the files I needed. I also reduced it down to what you need if you only want to use sendmail also.

If you want to use Sendmail, that is the easiest. Your dependencies are:

  • Zend/Exception.php
  • Zend/Mail.php
  • Zend/Mime.php
  • Zend/Mail/Exception.php
  • Zend/Mail/Transport/Abstract.php
  • Zend/Mail/Transport/Exception.php
  • Zend/Mail/Transport/Sendmail.php
  • Zend/Mime/Exception.php
  • Zend/Mime/Message.php
  • Zend/Mime/Part.php

And with those files, here is an example use:

<?php
// optionally
// set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/Zend');

require_once 'Zend/Mail.php';
require_once 'Zend/Mail/Transport/Sendmail.php';

$transport = new Zend_Mail_Transport_Sendmail();

$mail = new Zend_Mail();
$mail->addTo('user@domain')
     ->setSubject('Mail Test')
     ->setBodyText("Hello,\nThis is a Zend Mail message...\n")
     ->setFrom('sender@domain');

try {
    $mail->send($transport);
    echo "Message sent!<br />\n";
} catch (Exception $ex) {
    echo "Failed to send mail! " . $ex->getMessage() . "<br />\n";
}

If you need SMTP, then you have a few more dependencies to include. In addition to the above you need at least:

  • Zend/Loader.php
  • Zend/Registry.php
  • Zend/Validate.php
  • Zend/Mail/Protocol/Abstract.php
  • Zend/Mail/Protocol/Smtp.php
  • Zend/Mail/Transport/Smtp.php
  • Zend/Validate/Abstract.php
  • Zend/Validate/Hostname.php
  • Zend/Validate/Interface.php
  • Zend/Validate/Ip.php
  • Zend/Validate/Hostname/*
  • Zend/Mail/Protocol/Smtp/Auth/*

Then you can do something like this:

<?php

require_once 'Zend/Mail.php';
require_once 'Zend/Mail/Transport/Smtp.php';

$config    = array(//'ssl' => 'tls',
                   'port' => '25', //465',
                   'auth' => 'login',
                   'username' => 'user',
                   'password' => 'password');

$transport = new Zend_Mail_Transport_Smtp('smtp.example.com', $config);

$mail = new Zend_Mail();
$mail->addTo('user@domain')
     ->setSubject('Mail Test')
     ->setBodyText("Hello,\nThis is a Zend Mail message...\n")
     ->setFrom('sender@domain');

try {
    $mail->send($transport);
    echo "Message sent!<br />\n";
} catch (Exception $ex) {
    echo "Failed to send mail! " . $ex->getMessage() . "<br />\n";
}
like image 174
drew010 Avatar answered Dec 10 '22 11:12

drew010