【问题标题】:Codeigniter set email from in configCodeigniter 在配置中设置电子邮件
【发布时间】:2017-06-19 09:26:57
【问题描述】:

我想知道它是否能够在电子邮件的配置中定义 CI 电子邮件的 fromreply_to,如下所示:

$mail_config = Array(
    'protocol' => 'smtp',
    'smtp_host' => $school_custom['smtp_host'],
    'smtp_port' => $school_custom['smtp_port'],
    'smtp_user' => $school_custom['smtp_user'],
    'smtp_pass' => $school_custom['smtp_password'],
    'mailtype' => 'html',
    'from' => 'from_email',
    'reply_to' => 'reply_to_email'
);

$this -> load -> library('email', $mail_config);

我正在寻找这个的原因是因为我加载库的位置在我的函数的顶部,而设置 from 和 reply_to 的位置在底部,所以我想将它们与配置组合在一起,因为它们对于将要发送的所有电子邮件都是相同的。

我找不到任何关于此的内容,并且我在上面尝试的测试似乎不起作用,所以我不完全确定它是否可能。

提前感谢

【问题讨论】:

    标签: codeigniter email


    【解决方案1】:

    创建文件APPPATH.'config/custom_email.php':

    <?php
    $config = [
        'from_mail' => 'from@mail.com',
        'reply_to_email' => 'reply_to@email.com',
    ];
    

    APPPATH.'config/custom_mail.php'内自动加载文件:

    $autoload['config'] = array('custom_email');// line 106
    

    这样使用:

    $mail_config = Array(
        'protocol' => 'smtp',
        'smtp_host' => $school_custom['smtp_host'],
        'smtp_port' => $school_custom['smtp_port'],
        'smtp_user' => $school_custom['smtp_user'],
        'smtp_pass' => $school_custom['smtp_password'],
        'mailtype' => 'html',
        'from' => $this->config->item('from_mail'),
        'reply_to' => $this->config->item('reply_to_email')
    );
    
    $this -> load -> library('email', $mail_config);
    

    您还可以根据需要在该配置文件或其他配置文件中设置其他值。 如果该配置始终是静态配置,您可以传递配置文件中的所有值并直接使用manual loading 后面的一行代码加载它,如文档中所述。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-02
      • 2011-09-23
      • 2015-01-27
      • 2013-07-30
      • 2012-05-02
      • 1970-01-01
      • 1970-01-01
      • 2015-10-30
      相关资源
      最近更新 更多