public function mail()
{
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.qq.com';
$config['smtp_user'] = '596308403@qq.com';
$config['smtp_pass'] = '********';
$config['smtp_port'] = '25';
$config['charset'] = 'utf-8';
$config['mailtype'] = 'text';
$config['smtp_timeout'] = '5';
$config['newline'] = "\r\n";
$this->load->library ('email', $config);
$this->email->from ('596308403@qq.com', 'hello');
$this->email->to ('xxxxx@qq.com', 'xxxx');
$this->email->subject ('Test subject');
$this->email->message ('The content');
$this->email->send ();
// echo $this->email->print_debugger();
}
TP5使用PHPMailer发送邮箱
/**
* 系统邮件发送函数
* @param string $tomail 接收邮件者邮箱
* @param string $name 接收邮件者名称
* @param string $subject 邮件主题
* @param string $body 邮件内容
* @param string $attachment 附件列表
* @return boolean
*/
function send_mail($username,$password,$tomail, $name='', $subject = '短信平台', $body = '', $attachment = null,$formname="系统消息") {
if(empty($username))
return "smtp帐号不可为空";
if(empty($password))
return "smtp密码不可为空";
if(empty($tomail))
return "到达email地址不可为空";
$mail = new PHPMailer(); //实例化PHPMailer对象
$mail->CharSet = 'UTF-8'; //设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码
$mail->IsSMTP(); // 设定使用SMTP服务
$mail->SMTPDebug = 0; // SMTP调试功能 0=关闭 1 = 错误和消息 2 = 消息
$mail->SMTPAuth = true; // 启用 SMTP 验证功能
$mail->SMTPSecure = 'ssl'; // 使用安全协议
$mail->Host = "smtp.exmail.qq.com"; // SMTP 服务器
$mail->Port = 465; // SMTP服务器的端口号
$mail->Username = $username; // SMTP服务器用户名
$mail->Password = $password; // SMTP服务器密码
$mail->SetFrom($username, $formname);
$replyEmail = ''; //留空则为发件人EMAIL
$replyName = ''; //回复名称(留空则为发件人名称)
$mail->AddReplyTo($replyEmail, $replyName);
$mail->Subject = $subject;
$mail->MsgHTML($body);
$mail->AddAddress($tomail, $name);
if (is_array($attachment)) { // 添加附件
foreach ($attachment as $file) {
is_file($file) && $mail->AddAttachment($file);
}
}
return $mail->Send() ? true : $mail->ErrorInfo;
}