private function mailTo($email) { $user = M("user"); $userInfo = $user->field('id,username,password')->where("email = '{$email}'")->find(); $string = md5($userInfo['username'] . '+' . $userInfo['password']); $str = base64_encode($userInfo['username'] . '#>.<#' . $string); $id = $userInfo['id']; //完善后数据库读取 $url = 'http://127.0.0.1/object/index.php/home/Helpself/resetpwd/verify/' . $str; // $con = '<style class="fox_global_style"> div.fox_html_content { line-height: 1.5;} /* 一些默认样式 */ blockquote { margin-Top: 0px; margin-Bottom: 0px; margin-Left: 0.5em } ol, ul { margin-Top: 0px; margin-Bottom: 0px; list-style-position: inside; } p { margin-Top: 0px; margin-Bottom: 0px } </style><title>用户中心</title><h2 style="margi-top:35px;margin-left:25px;"><img src="http://i1.letvimg.com/img/201403/07/1512/logo.png"></h2><p style="margin-left:25px;font-size:14px; color:#444444; font-family:"微软雅黑";">点击按钮去重置密码:</p><p style="margin:20px 0 20px 25px;"><a href="'.$url.'" style="display:block; width:180px; height:43px; overflow:hidden; font-family:"微软雅黑"; line-height:43px; text-align:center; font-size:16px; background-color:#419ce3; border:1px solid #419ce3; color:#ffffff;text-decoration:none;" title="重置密码">重置密码</a></p><p style="margin-left:25px;font-size:14px; color:#444444; font-family:"微软雅黑";">或点击链接:<a href="'.$url.'" style="color:#529bef; font-size:14px; text-decoration:underline;">'.$url.'</a></p><p style="margin-left:25px;font-size:14px; color:#444444; font-family:"微软雅黑";">非常感谢您对我们的关心和支持!如有任何疑问,欢迎您随时<a href="http://aboutus.letv.com/contact/index.html" target="_blank" style="color:#529bef;">联系我们</a></p><p style="margin-left:25px;color:#c6c6c6; font-family:"微软雅黑"; font-size:14px;">这是一封自动发送的邮件,请不要直接回复</p><br><br><img style="display: none" src="http://scu.sohu.com/track/open.do?p=eyJlbWFpbF9pZCI6ICIxNDIyNjA4MzYzMjc2XzE0MTEzXzY3NThfMTUwMC5zYy0xMF8xMF8xMjdfMTA1LWluYm91bmQwJHpsdXRhb0BxcS5jb20iLCAiY2F0ZWdvcnlfaWQiOiA2Mjk3MiwgInVzZXJfaWQiOiAxNDExMywgInNpZ24iOiAiZTUyNDM4NTU1N2I0YmYwZmUwMmM1ZmI2Mjc0NTkyMDYiLCAibGFiZWwiOiAwfQ%3D%3D">'; $con = '<style class="fox_global_style"> div.fox_html_content { line-height: 1.5;} /* 一些默认样式 */ blockquote { margin-Top: 0px; margin-Bottom: 0px; margin-Left: 0.5em } ol, ul { margin-Top: 0px; margin-Bottom: 0px; list-style-position: inside; } p { margin-Top: 0px; margin-Bottom: 0px } </style><table style="-webkit-font-smoothing: antialiased;font-family:"微软雅黑", "Helvetica Neue", sans-serif, SimHei;padding:35px 50px;margin: 25px auto; background:rgb(247,246, 242); border-radius:5px" border="0" cellspacing="0" cellpadding="0" width="640" align="center"> <tbody> <tr> <td style="color:#000;"> </td> </tr> <tr><td style="padding:0 20px"><hr style="border:none;border-top:1px solid #ccc;"></td></tr> <tr> <td style="padding: 20px 20px 20px 20px;"> Hi ' . $userInfo['username'] . ', </td> </tr> <tr> <td valign="middle" style="line-height:24px;padding: 15px 20px;"> 感谢您的支持! <br> 请点击以下链接修改您的密码: </td> </tr> <tr> <td style="height: 50px;color: white;" valign="middle"> <div style="padding:10px 20px;border-radius:5px;background: rgb(64, 69, 77);margin-left:20px;margin-right:20px"> <a style="word-break:break-all;line-height:23px;color:white;font-size:15px;text-decoration:none;" href="' . $url . '">' . $url . '</a> </div> </td> </tr> <tr> <td style="padding: 20px 20px 20px 20px"> 请勿回复此邮件,如果有疑问,请联系我们:<a style="color:#5083c0;text-decoration:none" href="mailto:admin@lamp95.com">support@lamp95.com</a> </td> </tr> <tr> <td style="padding: 20px 20px 20px 20px"> - LAMP 95 团队 </td> </tr> <tr> <td style="padding:0 20px;"><hr style="border:none;border-top:1px solid #ccc;"></td> </tr> <tr> <td style="padding:0 20px;font-size:9pt; color:#b5b0b0"> <span style="float:left;">如果您想起了您的登录密码,请忽略此邮件。</span></td> </tr> </tbody> </table>'; // var_dump($userInfo);die; $mail = new \Org\Util\PHPMailer(); $mail->IsSMTP(); $mail->CharSet = 'UTF-8'; //设置邮件的字符编码,这很重要,不然中文乱码 $mail->SMTPAuth = true; //开启认证 $mail->Port = '25'; $mail->Host = 'smtp.163.com'; $mail->Username = '******'; $mail->Password = '******'; // $mail->AddReplyTo('*****@*****.**');//回复地址 $mail->From = '*****@*****.**'; $mail->FromName = '乐商'; $mail->AddAddress("{$email}"); $mail->Subject = '密码找回'; $mail->Body = "{$con}"; $mail->WordWrap = 80; // 设置每行字符串的长度 $mail->IsHTML(true); $res = $mail->Send(); if (!$res) { echo 3; } else { echo 0; } }
/** * @param String 收件人邮箱 * @param String 发送的内容 * @param String 邮件的主题 * @return boolean */ function sendMail($address, $msg, $project) { $mail = new \Org\Util\PHPMailer(); $mail->CharSet = "utf-8"; //设置采用utf8中文编码 $mail->IsSMTP(); //设置采用SMTP方式发送邮件 $mail->Host = C('email_host'); //设置邮件服务器的地址 smtp.qq.com $mail->Port = C('email_port'); //设置邮件服务器的端口,默认为25 gmail 443 $mail->From = C('email_username'); //设置发件人的邮箱地址 $mail->FromName = C('email_fromname'); //设置发件人的姓名 $mail->SMTPAuth = true; // 设置SMTP是否需要密码验证,true表示需要 $mail->Username = C('email_username'); $mail->Password = C('email_pwd'); $mail->Subject = $project; //设置邮件的标题 $mail->AltBody = "text/html"; // optional, comment out and test <a href="">abc</a> $mail->Body = $msg; //发送的内容 $mail->IsHTML(true); //设置内容是否为html类型 $mail->AddAddress($address); //设置收件的地址 if (!$mail->Send()) { //发送邮件 // $mail->ErrorInfo; 错误信息 return false; } else { return true; } }
protected function mail($email, $code, $id) { $Admin = D("Admin"); $reset_url = "http://" . $Admin->getConf('website_address') . U("Home/User/reset?code={$code}&id={$id}"); //$mail_info=$Admin->getConf('mail_info'); $mail_info = json_decode($Admin->getConf('mail_info'), true); $mail = new \Org\Util\PHPMailer(); $mail->IsSMTP(); // 使用SMTP方式发送 $mail->CharSet = 'UTF-8'; // 设置邮件的字符编码 $mail->Host = $mail_info["address"]; // 您的企业邮局服务器 $mail->Port = $mail_info["port"]; // 设置端口 $mail->SMTPAuth = true; // 启用SMTP验证功能 $mail->Username = $mail_info["mail"]; // 邮局用户名(请填写完整的email地址) $mail->Password = $mail_info["password"]; // 邮局密码 $mail->From = $mail_info["mail"]; //邮件发送者email地址 $mail->FromName = $mail_info["user"]; $mail->AddAddress($email, $email); //收件人地址,可以替换成任何想要接收邮件的email信箱,格式是AddAddress("收件人email","收件人姓名") $mail->IsHTML(true); // set email format to HTML //是否使用HTML格式 $mail->Subject = '密码重置'; //"PHPMailer测试邮件"; //邮件标题 $mail->Body = "亲爱的用户,<br /> 您好,这是我们网站的密码重置邮件,如果您未在我们网站进行此操作,请忽视此邮件。重置步骤<br /> 1.进入此地址:<a href='" . $reset_url . "'>" . $reset_url . "</a>;<br /> 2.输入用户名;<br /> 3.重置密码。"; //邮件内容 if (!$mail->Send()) { return 0; } else { return 1; } }