cakephp swiftmailer 配置

发布于 2024-09-24 07:43:46 字数 586 浏览 9 评论 0原文

您好,我在我的应用程序中使用 swiftmailer 组件,并且正在寻找一种方法来为 swiftmailer 提供单独的配置(可能在配置文件夹中?),以检查我正在使用的调试模式,从而使用不同的设置?

情况 1:在生产模式下使用简单的 smtp 服务器,无需身份验证。 情况 2:在调试模式下使用 gmail 设置或其他设置,因为我是在本地开发,

这可能吗?

设置代码案例 1:

$this->SwiftMailer->smtpHost = ''; 

设置代码案例 2:

        $this->SwiftMailer->smtpType = ''; 
        $this->SwiftMailer->smtpHost = ''; 
        $this->SwiftMailer->smtpPort =; 
        $this->SwiftMailer->smtpUsername = ''; 
        $this->SwiftMailer->smtpPassword = ''; 

hi i am using swiftmailer component in my app and am looking for a way to have a separate config (perhaps in config folder?) for swiftmailer that checks what debug mode i am using and thus uses different settings?

case 1: on production mode use simple smtp server without auth.
case 2: on debug mode use gmail settings or other settings since i am developing locally

is this possible?

the settings code case 1:

$this->SwiftMailer->smtpHost = ''; 

the settings code case 2:

        $this->SwiftMailer->smtpType = ''; 
        $this->SwiftMailer->smtpHost = ''; 
        $this->SwiftMailer->smtpPort =; 
        $this->SwiftMailer->smtpUsername = ''; 
        $this->SwiftMailer->smtpPassword = ''; 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷夜 2024-10-01 07:43:46

我认为最快的方法是:

<?php
    Configure::load('swiftmailer');
    $this->SwiftMailer->smtpType =
      Configure::read('SwiftMailer.'.Configure::read().'.smtpType');
    $this->SwiftMailer->smtpHost = 
      Configure::read('SwiftMailer.'.Configure::read().'.smtpHost');
    $this->SwiftMailer->smtpPort = 
      Configure::read('SwiftMailer.'.Configure::read().'.smtpPort');
    $this->SwiftMailer->smtpUsername = 
      Configure::read('SwiftMailer.'.Configure::read().'.smtpUsername');
    $this->SwiftMailer->smtpPassword = 
      Configure::read('SwiftMailer.'.Configure::read().'.smtpPassword');
?>

现在把它放在哪里。
我建议使用控制器构造函数,这样既漂亮又整洁。
对于这些值,您始终可以使用私有配置文件:

// /app/config/swiftmailer.php:
<?php
  $config['SwiftMailer'][0]['smtpType'] = 'value';
  $config['SwiftMailer'][0]['smtpHost'] = 'value';
  $config['SwiftMailer'][0]['smtpPort'] = 'value';
  $config['SwiftMailer'][0]['smtpUsername'] = 'value';
  $config['SwiftMailer'][0]['smtpPassword'] = 'value';

  $config['SwiftMailer'][1]['smtpType'] = 'value';
  $config['SwiftMailer'][1]['smtpHost'] = 'value';
  $config['SwiftMailer'][1]['smtpPort'] = 'value';
  $config['SwiftMailer'][1]['smtpUsername'] = 'value';
  $config['SwiftMailer'][1]['smtpPassword'] = 'value';

  $config['SwiftMailer'][2]['smtpType'] = 'value';
  $config['SwiftMailer'][2]['smtpHost'] = 'value';
  $config['SwiftMailer'][2]['smtpPort'] = 'value';
  $config['SwiftMailer'][2]['smtpUsername'] = 'value';
  $config['SwiftMailer'][2]['smtpPassword'] = 'value';
?>

您可以在 配置类 v 1.2配置类 v 1.3

它们的内容似乎是相同的,所以看起来从1.2到1.3没有改变。

希望有帮助。

I think the quickest way would be:

<?php
    Configure::load('swiftmailer');
    $this->SwiftMailer->smtpType =
      Configure::read('SwiftMailer.'.Configure::read().'.smtpType');
    $this->SwiftMailer->smtpHost = 
      Configure::read('SwiftMailer.'.Configure::read().'.smtpHost');
    $this->SwiftMailer->smtpPort = 
      Configure::read('SwiftMailer.'.Configure::read().'.smtpPort');
    $this->SwiftMailer->smtpUsername = 
      Configure::read('SwiftMailer.'.Configure::read().'.smtpUsername');
    $this->SwiftMailer->smtpPassword = 
      Configure::read('SwiftMailer.'.Configure::read().'.smtpPassword');
?>

Now where to put it on.
I would suggest the Controller constructor, that way it's nice and tidy.
For the values you can always use a private config file:

// /app/config/swiftmailer.php:
<?php
  $config['SwiftMailer'][0]['smtpType'] = 'value';
  $config['SwiftMailer'][0]['smtpHost'] = 'value';
  $config['SwiftMailer'][0]['smtpPort'] = 'value';
  $config['SwiftMailer'][0]['smtpUsername'] = 'value';
  $config['SwiftMailer'][0]['smtpPassword'] = 'value';

  $config['SwiftMailer'][1]['smtpType'] = 'value';
  $config['SwiftMailer'][1]['smtpHost'] = 'value';
  $config['SwiftMailer'][1]['smtpPort'] = 'value';
  $config['SwiftMailer'][1]['smtpUsername'] = 'value';
  $config['SwiftMailer'][1]['smtpPassword'] = 'value';

  $config['SwiftMailer'][2]['smtpType'] = 'value';
  $config['SwiftMailer'][2]['smtpHost'] = 'value';
  $config['SwiftMailer'][2]['smtpPort'] = 'value';
  $config['SwiftMailer'][2]['smtpUsername'] = 'value';
  $config['SwiftMailer'][2]['smtpPassword'] = 'value';
?>

You can find a more generic example on Configuration Class v 1.2 and Configuration Class v 1.3.

They seem to have the same content, so it seems that it hasn't changed from 1.2 to 1.3.

Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文