900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 关于PHP发送邮箱验证码功能介绍

关于PHP发送邮箱验证码功能介绍

时间:2020-07-09 21:34:32

相关推荐

关于PHP发送邮箱验证码功能介绍

关于PHP发送邮箱验证码功能介绍

PHP语言发送邮箱验证码,可以使用PHPMailer这个现成的类文件,完美集成实现邮箱发送验证码

前期准备:

a).PHPMailer下载地址:在git上获取最新版即可:/PHPMailer/PHPMailer

b).php必须开启:php_openssl

c).配置发送邮箱

1).位置

2).以下框中内容必须开启

2、使用示例:此处以QQ邮箱为例:

/*** 发送邮箱获取验证码*/

publicfunctionsendSMTEmail($email,$title,$content) {

$rs= array('code'=> 0, 'msg'=> '', 'info'=> array());

//引入phpmailer

require_once("./PHPMailer/PHPMailerAutoload.php");

$config= $this->getConfigPri();

$configpub= $this->getConfigPub();

$mail=new\PHPMailer();

// Enable verbose debug output

$mail->SMTPDebug = 0;

$mail->CharSet = "UTF-8";

// Set mailer to use SMTP

$mail->isSMTP();

// SMTP服务器地址

$mail->Host =$config['email_smtp'];

// Enable SMTP authentication

$mail->SMTPAuth = true;

// SMTP usernameSMTP邮箱地址

$mail->Username = $config['email_loginname'];

// SMTP password:SMTP邮箱授权码,并非QQ邮箱密码

$mail->Password =$config['email_pwd'];

// "ssl" SMTP邮箱登录方式

$mail->SMTPSecure =$config['email_smtp_secure'];

// TCP port to connect to邮箱端口号

$mail->Port =$config['email_smtp_port'];

//服务器域名

$mail->FromName =$configpub['site'];

//SMTP邮箱地址

$mail->From=$config['email_loginname'];

$mail->addAddress($email);

// Optional name

$mail->isHTML(true);

// Set email format to HTML

$mail->Subject =$title;

$mail->Body = $content;

// 发送邮件

$rs=$mail->Send();

if(!$rs){

return1001;

}

return$content;

}

//调用发送邮箱验证码方法

$this->sendSMTEmail('要发送的email', '标题', '邮件正文');

其中:$coinfig[]获取的皆为配置信息,如下图所示

总结:$mail->SMTPSecure = C('email_config.secure');//如果是QQ邮箱,必须设置为 ssl ; 并且下面的端口, 同步设置为 465 ; 否则一定不成功!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。