Home > Article > Backend Development > CodeIgniter uses smtp service to send html emails, codeignitersmtp_PHP tutorial
This article describes the example of CodeIgniter using the smtp service to send html emails. Share it with everyone for your reference. The details are as follows:
The email class provided by codeigniter is used to send emails,
Wiki address: http://codeigniter.org.cn/user_guide/libraries/email.html
In actual development, we encountered the following problems. To summarize:
1. The wiki explains that the configuration file can be extracted separately, and email.php is placed in the config folder,
For the configuration of email.php, there are a few points that need to be explained:
1) The smtp service used in general testing, such as the mailboxes of 126 and 163, all use this protocol, so the protocol is smtp
2) Corporate marketing emails are generally in html. In this case, you need to configure the mailtype to html
The email.php configuration file I wrote under the example:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /* |------------------------------------ | Email Config |------------------------------------ | by chaichunyan | */ $config['protocol'] = 'smtp'; $config['smtp_host'] = 'smtp.126.com'; $config['smtp_user'] = 'xxx@126.com'; $config['smtp_pass'] = 'xxx'; $config['smtp_port'] = '25'; $config['charset'] = 'utf-8'; $config['wordwrap'] = TRUE; $config['mailtype'] = 'html';
2) The html used in the sent html attribute value needs to be processed
$send_msg = str_replace("\"", "", $msg); $this->email->message($send_msg);
3) When developing, it is recommended to turn on the debug information, because if you frequently use the 126 mailbox to send external emails,
Firstly, it may be considered as spam, and more importantly, it may be blocked by 126 :(
I hope this article will be helpful to everyone’s PHP programming based on CodeIgniter.