how to configure SMTP in codeigniter application?

2019-09-14 18:41发布

问题:

I'm new to SMTP, sendmail, and mail() function in php codeigniter.

I'm trying to configure SMTP mail protocol in my codeigniter application. Make all settings, SMTP port, sender mail, user id, password for single user i.e. admin@example.com. It working fine.

My question is, it is possible to setup two SMTP user account in single application ?

For example I want to set info@example.com and admin@example.com, so these two users can send mails to customers.

回答1:

You can use it by only changes in config : as like

$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'xxx', // First user authenticate
    'smtp_pass' => 'xxx',
    'mailtype'  => 'html', 
    'charset'   => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");

// Set to, from, message, etc.

$result = $this->email->send();

and

$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'yyy', // Second user authenticate
    'smtp_pass' => 'zzzz',
    'mailtype'  => 'html', 
    'charset'   => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");

// Set to, from, message, etc.

$result = $this->email->send();

But only one thing is that you have to configure your both mail user at server. Thanks