码迷,mamicode.com
首页 > 其他好文 > 详细

邮箱发送验证码

时间:2018-05-23 15:29:45      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:服务器   ESS   socket   cti   extension   使用   去掉   address   debug   

public function email()
{
//$email=input(“email”);
$email = “m13696693413@163.com”;
//return $email;
$sendmail = ‘1902479163@qq.com’; //发件人邮箱
$sendmailpswd = “jbdzddubdslobacc”; //客户端授权密码,而不是邮箱的登录密码!
$send_name = ‘lh’;// 设置发件人信息,如邮件格式说明中的发件人,
$toemail = $email;//定义收件人的邮箱
$to_name = ‘hl’;//设置收件人信息,如邮件格式说明中的收件人

$mail = new \phpmailer\PHPMailer();

$mail->isSMTP();// 使用SMTP服务
$mail->CharSet = “utf8”;// 编码格式为utf8,不设置编码的话,中文会出现乱码
$mail->Host = “smtp.qq.com”;// 发送方的SMTP服务器地址
$mail->SMTPAuth = true;// 是否使用身份验证
$mail->Username = $sendmail;//// 发送方的
$mail->SMTPDebug = 1;
$mail->Password = $sendmailpswd;//客户端授权密码,而不是邮箱的登录密码!
$mail->SMTPSecure = “ssl”;// 使用ssl协议方式
$mail->Port = 465;// qq端口465或587)
$mail->setFrom($sendmail, $send_name);// 设置发件人信息,如邮件格式说明中的发件人,
$mail->addAddress($toemail, $to_name);// 设置收件人信息,如邮件格式说明中的收件人,
$mail->addReplyTo($sendmail, $send_name);// 设置回复人信息,指的是收件人收到邮件后,如果要回复,回复邮件将发送到的邮箱地址
$mail->Subject = “邮箱验证码”;// 邮件标题

$code=rand(100000,999999);
session(“code”,$code);
//return $code.”—-“.session(“code”);
$mail->Body = “邮件内容是 您的验证码是:$code,如果非本人操作无需理会!”;// 邮件正文

$mail->AltBody = “This is the plain text纯文本”;// 这个是设置纯文本方式显示的正文内容,如果不支持Html方式,就会用到这个,基本无用
if ($mail->Send()) { // 发送邮件
echo “发送成功”;

} else {
echo “发送失败”;
}
}

出错类型
1,SMTP Error: Could not connect to SMTP host.
出现这个问题的原因是因为
public function IsSMTP() {
$this->Mailer = ‘SMTP’; //小写换成了大写
}
2,Could not instantiate mail function.
这是因为修改了PHPMailer里面的SMTP,小写换成了大写
public function IsSMTP() {
$this->Mailer = ‘SMTP’;
}
这里的小写我没有换成大写
switch($this->Mailer) {
case ‘sendmail’:
return $this->SendmailSend($header, $body);
case ‘SMTP’: //这里的小写也要换成大写;
return $this->SmtpSend($header, $body);
default:
return $this->MailSend($header, $body);
}

3,PHP Unable to find the socket transport ssl
解决方案,在php。ini里面找到extension=php_openssl.dll 去掉注释就好;
目前遇到这些问题,以及解决方案。

邮箱发送验证码

标签:服务器   ESS   socket   cti   extension   使用   去掉   address   debug   

原文地址:https://www.cnblogs.com/xin521/p/9076995.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!