Cause:
When using codeigniter, we often need to send emails to remind ourselves or notify others. At this time, we can use the class email provided by codeigniter to complete our work.
Introduction:
By viewing the email. php file, we can see that codeigniter can use three Protocols to send Emails:
VaR $ protocol = "mail"; // mail/sendmail/SMTP
We use SMTP here.
Usage:
First, select email. I chose Google's Gmail here. Gmail is generally not considered as spam, but Gmail's SMTP method is SSL, therefore, SSL must be installed on the host before it can be used.
$config['protocol'] = 'smtp';$config['smtp_host'] = 'ssl://smtp.gmail.com';$config['smtp_user'] = 'youremail@gmail.com';$config['smtp_pass'] = 'yourpassword';$config['smtp_port'] = '465';$config['charset'] = 'utf-8';$config['mailtype'] = 'text';$config['smtp_timeout'] = '5';$config['newline'] = "\r\n";$this->load->library ('email', $config);$this->email->from ('from@email.com', 'From email name');$this->email->to ('to@email.com', 'To email name');$this->email->bcc ('bcc@email.com');$this->email->subject ('Test subject');$this->email->message ('The content');$this->email->send ();
Run the following command to check whether the job works:
echo $this->email->print_debugger();exit;