Codeigniter从配置中设置电子邮件

时间:2017-06-19 09:26:58

标签: codeigniter email

我想知道它是否能够在电子邮件的配置中定义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在底部,所以我想将它们与配置组合在一起,因为它们对于将要发送的所有电子邮件都是相同的。

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

提前完成

1 个答案:

答案 0 :(得分:0)

创建文件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之后的一行代码直接加载它。