使用 邮箱配置 激活码 用于 用户注册激活
我们使用 phpmailer 插件 完成
1 引入 文件到 thinkphp 下的 vendor
2 在 配置参数 中配置 imap
1 function sendMail($reciver, $recivername, $subject = "", $body="", $sender="751971678@qq.com", $sendername="刘涛") 2 { 3 vendor('PHPMailer.PHPMailerAutoload'); 4 5 $phpMailer = new PHPMailer(); 6 7 //发送邮件服务器配置 8 $phpMailer->isSMTP(); // Set mailer to use SMTP 9 $phpMailer->Host = C('MAIL_CONFIG.SMTP_HOST'); // Specify main and backup SMTP servers 10 $phpMailer->SMTPAuth = true; // Enable SMTP authentication 11 $phpMailer->Username = C('MAIL_CONFIG.USER_NAME'); // SMTP username 12 $phpMailer->Password = C('MAIL_CONFIG.PASSWORD'); // SMTP password 13 $phpMailer->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted 14 $phpMailer->Port = C('MAIL_CONFIG.PORTS'); // TCP port to connect to 15 16 //发送邮件用户配置 17 $phpMailer->setFrom($sender, $sendername); 18 $phpMailer->addAddress($reciver, $recivername); // Add a recipient 19 20 $phpMailer->isHTML(true); // Set email format to HTML 21 22 //邮件内容及主题 23 $phpMailer->Subject = $subject; 24 $phpMailer->Body = $body; 25 26 if(!$phpMailer->send()) { 27 throw new ThinkException($phpMailer->ErrorInfo, 0); 28 } else { 29 return true; 30 } 31 }