900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > php 126怎么设置发送邮箱验证码 邮箱发送验证码(示例代码)

php 126怎么设置发送邮箱验证码 邮箱发送验证码(示例代码)

时间:2021-09-30 03:18:41

相关推荐

php 126怎么设置发送邮箱验证码 邮箱发送验证码(示例代码)

public function email()

{

//$email=input(“email”);

$email = “[emailprotected]”;

//return $email;

$sendmail = ‘[emailprotected]’; //发件人邮箱

$sendmailpswd = “jbdzddubdslobacc”; //客户端授权密码,而不是邮箱的登录密码!

$send_name = ‘lh’;// 设置发件人信息,如邮件格式说明中的发件人,

$toemail = $email;//定义收件人的邮箱

$to_name = ‘hl’;//设置收件人信息,如邮件格式说明中的收件人

$mail = new \phpmailer\PHPMailer();

$mail->isSMTP();// 使用SMTP服务

$mail->CharSet = “utf8”;// 编码格式为utf8,不设置编码的话,中文会出现乱码

$mail->Host = “”;// 发送方的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 去掉注释就好;

目前遇到这些问题,以及解决方案。

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