zoukankan      html  css  js  c++  java
  • ci中使用mail类

    <?php
    defined('BASEPATH') OR exit('No direct script access allowed');

    class Index extends CI_Controller {
        function __construct()
            {
                parent::__construct();
            }
        public function index()
        {
            $this->load->view('index');
        }
        // 注册
        public function receive(){
            $act=isset($_GET['act']) ? $_GET['act'] : '';
            $pdo=new PDO("mysql:host=127.0.0.1;dbname=news","root","root");
            $pdo->exec("set names utf8");
            if ($act=="zhuce") {
                // 用户注册
                $name=$this->input->post("name");
                $pwd=md5($this->input->post("pwd"));
                $em=$this->input->post("email");
                $key=md5("hello world");
                $start=0;
                $time=time();
                // 添加用户信息
                $sql="insert into user value(null,'$name','$pwd','$em','$start','$key')";
                if ($pdo->exec($sql)) {
                    // 添加成功发送激活邮箱
                    $url="http://localhost/day9.22/index.php/index/receive?act=jihuo&name=".base64_encode($name)."&pwd=$pwd&key=$key&start=$start&time=$time";
                    $title="用户注册激活";
                    $content="请点击下面链接完成注册:<a href='$url'>$url</a>";
                    $user="来自";
                    // $address=$email;
                    // 引入发送邮箱类
                    $this->load->library('email');
                    // 配置邮件参数
                    $config['protocol'] = 'smtp';
                    $config['smtp_host'] = 'smtp.163.com'; //使用邮箱地址
                    $config['smtp_user'] = '15175881112@163.com'; //发送人邮箱
                    $config['smtp_pass'] = '1593578qqQQ'; //发送人邮箱pop3密码
                    $config['smtp_port'] = '25'; //使用端口号
                    $config['mailtype'] = 'html'; //发送邮箱类型
                    $config['charset'] = 'utf-8';
                    // $config['wordwrap'] = TRUE;
                    $this->email->initialize($config);
                    $this->email->from('15175881112@163.com', $user); //发送人邮箱
                    $this->email->to($em);
                    // $this->email->cc('another@another-example.com'); //抄送
                    // $this->email->bcc('them@their-example.com'); //密送

                    $this->email->subject($title); //邮件标题
                    $this->email->message($content); //邮件内容

                    if($this->email->send()){
                        echo "发送成功,请验证";
                        header("mail.qq.com");
                    }
                    else{
                        echo $this->email->print_debugger();
                    }
                }
            }elseif ($act=="jihuo") {
                // 用户验证邮箱
                $name=base64_decode($this->input->get('name'));
                $pwd=$this->input->get('pwd');
                $key=$this->input->get('key');
                $time=$this->input->get('time');
                $sql="select * from user where name='$name'";
                $res=$pdo->query($sql)->fetch(PDO::FETCH_ASSOC);
                if ($res['key']!=$key) {
                    echo "请不要恶意注册";
                    die;
                }
                // if (time()-$time>1800) {
                //     die("激活已经失效,请重新注册");
                // }
                if ($res['start']==1) {
                    echo "已经激活过,请登陆";
                    header("Location:receive?act=denglu");
                    die;
                     // redirect('act=denglu');
                }
                $sql2="update user set start=1 where name='$name'";
                if ($pdo->exec($sql2)) {
                    echo "激活成功,请登陆";
                    header("receive?act=denglu");
                    die;
                }else{
                    echo "激活失败,请重新注册";
                    header("refresh:3;receive");
                    die;
                }
            }elseif ($act=="denglu") {
                // 用户登陆提供登陆表单
                echo "denglu";
            }else{
                // 注册页面
                $this->load->view('index');
            }
        }
    }
  • 相关阅读:
    关于dubbo创建服务和引用服务时,会报错:cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 问题的解决
    解决 Maven工程运行报错Failed to clean project: Failed to delete
    Linux学习_004_使用CentOS 7.5卸载自带jdk安装自己的JDK1.8
    Linux下的JDK和OpenJDK有什么具体的区别
    常用的大数据技术有哪些?
    如何隐藏你的 Linux 的命令行历史
    Securi-Pi:使用树莓派作为安全跳板
    在 Linux 上管理加密密钥的最佳体验
    在 Linux 下使用任务管理器
    在 Linux 中安装 Lighttpd Web 服务器
  • 原文地址:https://www.cnblogs.com/wepe/p/7424608.html
Copyright © 2011-2022 走看看