application.ini中的多个Zend_Mail配置 [英] Multiple Zend_Mail configurations in application.ini

查看:106
本文介绍了application.ini中的多个Zend_Mail配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Zend Framework.

I'm am using Zend Framework.

我需要在Zend_Mail的application.ini中放入多个邮件配置(使用Zend_Application_Resource_Mail).是否可以使用Zend Framework中的标准类来做到这一点,还是我需要创建自己的类?

I need to put multiple mail configurations in application.ini for Zend_Mail (using Zend_Application_Resource_Mail). Is it possible to do this using the standard classes in Zend Framework or do I need to create my own class?

我正在使用Zend Framework的最新稳定版本.

I am using the latest stable version of Zend Framework.

感谢您的回答

推荐答案

似乎无法使用Zend_Application_Resource_Mail为Zend_Mail设置多种配置.

It does not appear to be possible to set multiple configurations for Zend_Mail with Zend_Application_Resource_Mail.

您可以将各种配置添加到application.ini,但是您必须编写自己的类/函数以使所需的配置处于活动状态.

You could add the various configurations to application.ini but you will have to write your own class/functions to make the desired configuration active.

Zend_Application_Resource_Mail设置的必须覆盖的内容是Zend_Mail::setDefaultTransport($newTransport);Zend_Mail::setDefaultReplyTo($email);Zend_Mail::setDefaultFrom($email);.

The things that are set by Zend_Application_Resource_Mail that you will have to override are Zend_Mail::setDefaultTransport($newTransport);, Zend_Mail::setDefaultReplyTo($email);, and Zend_Mail::setDefaultFrom($email);.

我测试了一些东西,发现可以轻松完成.

I tested something and found an easy thing you can do.

在application.ini中设置您这样的不同配置:

Set up your different configurations like this in application.ini:

mail_config.mail_test.transport.type = smtp
mail_config.mail_test.transport.host = "smtp.example.com"
mail_config.mail_test.transport.auth = login
mail_config.mail_test.transport.username = myUsername
mail_config.mail_test.transport.password = myPassword

mail_config.mail_test.defaultFrom.email = john@example.com
mail_config.mail_test.defaultFrom.name = "John Doe"
mail_config.mail_test.defaultReplyTo.email = Jane@example.com
mail_config.mail_test.defaultReplyTo.name = "Jane Doe"

请注意我们如何在mail_config下设置选项.这将是要应用的一组选项. mail_test是示例配置.您可以通过设置mail_config.mail_test2mail_config.corporate_mailmail_config.production等来设置多个.

Note how we are setting up options under mail_config. This will be the set of options to apply. mail_test is an example configuration. You can have multiple by setting mail_config.mail_test2, mail_config.corporate_mail, or mail_config.production etc.

接下来,创建一个从Zend_Application_Resource_Mail扩展的空类.最好将其命名并放置,以便可以自动加载.

Next, create an empty class that extends from Zend_Application_Resource_Mail. Preferably, it should be named and placed so it can be autoloaded.

课程:

<?php

class Application_Service_MailSettings extends Zend_Application_Resource_Mail { }

现在,这是如何使用其他内容轻松覆盖默认邮件配置的方法.

Now, here is how to override the default mail configuration easily with something else.

此示例假定您在控制器中:

This example assumes you are in a controller:

    // get the bootstrap, so we can get mail_config options
    $bootstrap = $this->getInvokeArg('bootstrap');
    $options   = $bootstrap->getOption('mail_config');

    // initialize the resource loader with the options from mail_config.mail_test
    $mailSettings = new Application_Service_MailSettings($options['mail_test']);
    $mailSettings->init();  // call init() so the settings are applied

    // now the default transport, from, and reply to are set using mail_config.mail_test options.

    // to use a different set of options, just do
    // $mailSettings = new Application_Service_MailSettings($options['other_config');

只需很少的新代码即可完成您想要的工作.

This should accomplish what you want with very little new code.

这篇关于application.ini中的多个Zend_Mail配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆