google邮箱 发送

google邮箱 发送

前期准备
一、申请google 邮箱账号 https://mail.google.com/
二、配置google 邮箱开启 pop/imap

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

三、创建应用密码,发送验证码时填写此密码
Create & use app passwords
Important: To create an app password, you need 2-Step Verification on your Google Account.

If you use 2-Step-Verification and get a “password incorrect” error when you sign in, you can try to use an app password.

Go to your Google Account.
Select Security.
Under “How you sign in to Google,” select 2-Step Verification.
At the bottom of the page, select App passwords.
Enter a name that helps you remember where you’ll use the app password.
Select Generate.
To enter the app password, follow the instructions on your screen. The app password is the 16-character code that generates on your device.
Select Done.
If you’ve set up 2-Step Verification but can’t find the option to add an app password, it might be because:

Your Google Account has 2-Step Verification set up only for security keys.
You’re logged into a work, school, or another organization account.
Your Google Account has Advanced Protection.
Tip: Usually, you’ll need to enter an app password once per app or device.
四、代码编辑
引用 PHPMailer

	//端口配置
	 $Host = "smtp.gmail.com";
	 $SMTPSecure = "ssl";
	 $Port = 465;
	 
     $mail = new \PHPMailer(); //实例化
     $mail->IsSMTP(); // 启用SMTP 
      $mail->SMTPDebug = 1;
      $mail->Host = $Host; //SMTP服务器 以163邮箱为例子
      $mail->SMTPSecure = $SMTPSecure;
      $mail->Port = $Port;  //邮件发送端口
      $mail->SMTPAuth = true;  //启用SMTP认证
      $mail->CharSet = "UTF-8"; //字符集
      $mail->Encoding = "base64"; //编码方式 
      $mail->Username = $this->web_email;  //你的邮箱
      $mail->Password = $this->web_email_pass;  //你的密码
      $mail->Subject = $title; //邮件标题
      $mail->From = $this->web_email;  //发件人地址(也就是你的邮箱)
      $mail->FromName = "";  //发件人姓名
      $mail->AddAddress($user_email, "");//添加收件人(地址,昵称)
      //$mail->AddAttachment($path,'投稿附件.'.$filetype);
      //$mail->AddAttachment('投稿附件.docx',$name); // 添加附件,并指定名称
      $mail->IsHTML(true); //支持html格式内容
      //$mail->AddEmbeddedImage("logo.jpg", "my-attach", "logo.jpg"); //设置邮件中的图片
      $text = $content;
      $mail->Body = $text;
      $result = $mail->Send();

特别注意,服务器使用国外服务器

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值