需要自己到phpmailer官网download plugins,然后引用实例调用sendMail(地址)发送就行了,关于加密解密这个要自己定比如时间限制 ,验证安全串,这个自己视情况而定
<?php
/**
* xincheng_qiao@163.com
* @author xincheng
*/
class MailAction extends Action
{
function send($address,$title,$content)
{
header('Content-type:text/html;charset=utf-8');
vendor('PHPMailer.class#PHPMailer');//这个是基于thinkphp的调用
// 也可以根据需要直接require('PHPMailer.class');
$mail=new PHPMailer(ture);
$mail->IsSMTP();
try {
$mail->Port = 'SNEDMAIL_PORT';//端口号:25...
$mail->Host='SENDMAIL_HOST';//smtp服务商:smtp.163.com
$mail->SMTPAuth=true;
$mail->Username='SENDMAIL_USER';//邮箱账号:xxx@163.com
$mail->Password='SENDMAIL_PASS';//邮箱密码:******
$mail->CharSet='UTF-8';
$mail->Encoding = "base64";
$mail->AddAddress($address);
$mail->SetFrom('SENDMAIL_USER', 'COMPANY');//发件人邮箱,名字
$mail->WordWrap = 80;
$mail->IsHTML(true);
$mail->Subject=$tittle;
$mail->Body =$content;
$mail->AltBody =”text/html”;
return($mail->Send());
} catch (phpmailerException $e) {
echo $e->errorMessage(),1;exit; //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); exit;//Boring error messages from anything else!
}
}
public function mailEncrypt($umail)
{
//解密url 验证参数(难易自定)
}
public function mailDecrypt($umail)
{
//加密url 参数(难易自定,可以把时间写进参数,用来做验证)
}
public function sendMail($mail)
{
$tittle = "change your password";
$email_encode = $this->mailEncrypt($mail);
$url = "http://sites/test/index.php/Admin/changePass/umail/".$email_encode;
$message= '<p>您好:</p> 请尽快点击这个链接完成密码的修改 <a href="'.$url.'">'.$url.'</a><br/><br/> 在使用过程中,请给予宝贵意见,谢谢! '. "$companyname";
$content = '<html><head><meta http-equiv=”Content-Language” content=”zh-cn”> <meta http-equiv=”Content-Type” content=”text/html;
charset=utf-8″></head><body>'.$message.'</body></html>';
return $this->send($mail,$title,$content);
}
}
?>