将Zend框架最小化到Zend_Mail?

Big*_*lue 4 php frameworks zend-framework zend-mail

可能重复:
使用没有实际框架的Zend Framework组件?

我只需要Zend Framework的Zend_Mail函数,但整个框架大小约为300MB.有没有办法将其简化为基础知识和Zend_Mail以节省一些磁盘空间?

dre*_*010 15

是的,之前我曾使用Zend_Mail和SMTP独立,这里是我需要的文件.如果你只想使用sendmail,我也把它减少到你需要的东西.

如果你想使用Sendmail,这是最简单的.你的依赖是:

  • Zend公司/ Exception.php
  • Zend公司/ Mail.php
  • Zend公司/ Mime.php
  • Zend公司/邮件/ Exception.php
  • Zend公司/邮件/运输/ Abstract.php
  • Zend公司/邮件/运输/ Exception.php
  • Zend公司/邮件/运输/ Sendmail.php
  • Zend公司/ MIME/Exception.php
  • Zend公司/ MIME/Message.php
  • Zend公司/ MIME/Part.php

有了这些文件,这里有一个示例用法:

<?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";
}
Run Code Online (Sandbox Code Playgroud)

如果您需要SMTP,那么您还需要包含一些依赖项.除了上述内容,您至少需要:

  • Zend公司/ Loader.php
  • Zend公司/ Registry.php
  • Zend公司/ Validate.php
  • Zend公司/邮件/协议/ Abstract.php
  • Zend公司/邮件/协议/ Smtp.php
  • Zend公司/邮件/运输/ Smtp.php
  • Zend公司/验证/ Abstract.php
  • Zend公司/验证/ Hostname.php
  • Zend公司/验证/ Interface.php
  • Zend公司/验证/ Ip.php
  • Zend公司/验证/主机名/*
  • Zend公司/邮件/协议/ SMTP /认证/*

然后你可以做这样的事情:

<?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";
}
Run Code Online (Sandbox Code Playgroud)