$sendmail = "你的邮箱"; //发件人邮箱
$sendmailpswd = "你的密码"; //客户端授权密码,而不是邮箱的登录密码,就是手机发送短信之后弹出来的一长串的密码
$send_name = 'XXXX'; // 设置发件人信息,如邮件格式说明中的发件人,
$code = sixDigitVerificationCode(6); //网上找,这我自己写的六位随机数
$toemail= $toeMail; //收件人的邮箱
$to_name = '厦门XXXX科技信息有限公司'; //设置收件人信息,如邮件格式说明中的收件人
$title = 'XX邮箱验证';
$subject = "=?GBK?B?".base64_encode('邮件主题')."?="; //解决邮件主题乱码问题,GBK编码格式
$header = "From: 发件人姓名 ".$sendmail;
$header .= "MIME-Version: 1.0";
$header .= "Content-type: text/html; charset=utf-8"; //邮件内容为utf-8编码
$header .= "Content-Transfer-Encoding: 8bit"; //注意header的结尾,只有这个后面有\r
ini_set('sendmail_from', 'username@domain.com'); //解决mail的一个bug
$emaildate=date('Y-m-d h:i:s',time());
$emailcontent = "";
$emailcontent.='<html><head></head><body><div style="font-family:黑体;min-height:300px; background:#0099cb;min-width:300px;max-width: 1000px;border: 0px solid #ccc; margin: auto;">';
$emailcontent.='<div style="width: 100%;font-size:20px;text-align: center;background: #4484c5; height: 50px;color: #FFF;line-height: 50px">确认您的邮箱地址</div>';
$emailcontent.='<div style="padding: 20px;color: #fff">';
$emailcontent.='<h3>尊敬的【'.$toeMail.'】您好:</h3>';
$emailcontent.='<p style="line-height: 30px">在创建XX账号之前,您需要完成一个简单的步骤!</p>';
$emailcontent.='<p style="line-height: 30px">让我们确保这是正确的邮件地址!</p>';
$emailcontent.='<p style="line-height: 30px">请输入此验证码以开始使用XX!</p>';
$emailcontent.='<h3 style="line-height: 30px; font-size: 26px">'.$code.'</h3>';
$emailcontent.='<p style="line-height: 30px">验证码10分钟后过期,请勿直接回复!</p>';
$emailcontent.='<p style="text-align: right; padding-right: 20px">谢谢</p>';
$emailcontent.='<p style="text-align: right; padding-right: 20px">XX平台</p>';
$emailcontent.='<p style="text-align: right; padding-right: 20px">'.$emaildate.'</p>';
$emailcontent.='</div>';
$emailcontent.='</div></body></html>';
$mail = new PHPMailer(); //实例化mail类 百度一下, 下载好放到你的项目里
$mail->isSMTP(); // 使用SMTP服务
$mail->CharSet = "utf8"; // 编码格式为utf8,不设置编码的话,中文会出现乱码
$mail->Host = "smtp.mxhichina.com"; //这个是阿里云的, 其他的你们百度下 发送方的SMTP服务器地址
$mail->SMTPAuth = true; // 是否使用身份验证
$mail->Username = $sendmail; // 发件人地址
$mail->Password = $sendmailpswd; //客户端授权密码,而不是邮箱的登录密码!
$mail->SMTPSecure = "ssl"; // 使用ssl协议方式
$mail->Port = 465; //sina端口110或25) //qq 465 587
$mail->IsHTML(true); //支持html格式内容
$mail->setFrom($sendmail, $send_name); // 设置发件人信息,如邮件格式说明中的发件人,
$mail->addAddress($toemail, $to_name); // 设置收件人信息,如邮件格式说明中的收件人,
$mail->addReplyTo($sendmail, $send_name);// 设置回复人信息,指的是收件人收到邮件后,如果要回复,回复邮件将发送到的邮箱地址
$mail->Subject = $title; // 邮件标题
$mail->Body = $emailcontent; // 邮件正文
$e = $mail->send();
//$mail->AltBody = "This is the plain text纯文本";// 这个是设置纯文本方式显示的正文内容,如果不支持Html方式,就会用到这个,基本无用
if(!$e){
return [
'code' => 0,
'data' => [],
'msg' => $mail->ErrorInfo //错误信息
];//返回数据格式自己定义的一个函数
}else{
return [
'code' => 200,
'data' => $code, //六位随机数
'msg' => ""
];
}点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号