Zend框架:如何在配置文件中设置默认的邮件传输方式?

4
我知道默认的邮件传输方式可以在引导文件中设置,但如何在 app.ini 文件中设置?基本上,我想在本地 Windows 系统上使用 SMTP 传输,在生产服务器上使用常规邮件传输。
编辑:我已经在 app.ini 中使用了 这些设置
谢谢。
3个回答

7
如果您的生产服务器是*nix系统
[production]
resources.mail.transport.type = sendmail
[development : production]
resources.mail.transport.type = smtp
resources.mail.transport.host = smtp.example.com

我已经尝试使用transport.type = smtp,但我一直收到异常,Zend显然无法加载“smtp”,我正在使用Zend Framework 1.12。 - Andy

4

您可能在寻找:

 resources.mail.transport.register = true ; True by default

完整示例:如果您处于生产环境中,将使用第一个传输方式;如果在开发环境中,则将使用开发模式。非常简单,不是吗?

[production]
resources.mail.transport.type = smtp
resources.mail.transport.host = "smtp.example.com"
resources.mail.transport.auth = login
resources.mail.transport.username = myUsername
resources.mail.transport.password = myPassword
resources.mail.transport.register = true ; True by default

resources.mail.defaultFrom.email = john@example.com
resources.mail.defaultFrom.name = "John Doe"
resources.mail.defaultReplyTo.email = Jane@example.com
resources.mail.defaultReplyTo.name = "Jane Doe"


[development]
resources.mail.transport.type = smtp
resources.mail.transport.host = "smtp2.example.com"
resources.mail.transport.auth = login2
resources.mail.transport.username = myUsername
resources.mail.transport.password = myPassword
resources.mail.transport.register = true ; True by default

resources.mail.defaultFrom.email = john@example.com
resources.mail.defaultFrom.name = "John Doe"
resources.mail.defaultReplyTo.email = Jane@example.com
resources.mail.defaultReplyTo.name = "Jane Doe"

来源: http://framework.zend.com/manual/1.12/zh/zend.application.available-resources.html

zend.application.available_resources是Zend Framework 1中用来查看应用程序资源的对象。该对象可以让您轻松地检查当前的模型、视图、插件、插件路径和helper等信息。

此外,您还可以通过在Bootstrap类中使用getPluginResource方法来自定义可用资源,以便将它们添加到此对象中。


这正是我在“编辑”中提到的来源。我认为“register”与设置默认值不同。“当实例化传输时,它会自动注册到Zend_Mail。但是,通过将transport.register指令设置为FALSE,该行为不再发生。” - understack
@understack,一旦您有多个传输方式,您就可以注意到它的结果。 - tawfekov

0

注意以下代码无法正常工作,会抛出异常:

resources.mail.transport.type = smtp

我们需要使用Zend_Mail_Transport_Smtp而不仅仅是smtp。请参阅下面的正确答案:

[production]
resources.mail.transport.type = sendmail
[development : production]
resources.mail.transport.type       = Zend_Mail_Transport_Smtp
resources.mail.transport.host       = "smtp.server.com"
resources.mail.transport.auth       = login
resources.mail.transport.username   = "myLogin"
resources.mail.transport.password   = "myPasswd"

来源:http://framework.zend.com/issues/browse/ZF-9802


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接