CodeIgniter 3 如何发送 Email 邮件

教你如何在 CodeIgniter 3 中发送邮件

请在你需要发送 Email 的控制器里写下如下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Liuwei extends CI_Controller {

public function sendEmail()
{
$title = '我是刘伟'; // 邮件的标题
$mes = '哈哈,你好呀!我的网站是: https://darrenliuwei.com'; // 邮件的内容
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.qq.com';
$config['smtp_port'] = 25;
$config['smtp_crypto'] = 'tls';
$config['smtp_user'] = '[email protected]'; // 请将邮箱换成你自己的邮箱
$config['smtp_pass'] = '*************'; // 请替换为你自己的QQ邮箱授权码

$this->email->initialize($config);
$this->email->set_newline("\r\n");

$this->email->from('[email protected]', 'liuwei'); // 请将邮箱换成你自己的邮箱
$this->email->to('[email protected]'); // 要发送给谁
// $this->email->cc('[email protected]');
// $this->email->bcc('[email protected]');

$this->email->subject($title);
$this->email->message($mes);

if (!$this->email->send())
{
echo $this->email->print_debugger(); // 如果邮件发送失败,就打印错误报告
}
}
}


刘伟 wechat
欢迎您扫一扫上面的微信公众号( 或者搜索:darrenliuwei )订阅
如果觉得本文对您有启发,可以随意打赏一点鼓励我继续更新!