腾讯企业邮箱:创建邮件授权码

申请官网

腾讯企业邮箱

绑定

在这里插入图片描述

生成密码

在这里插入图片描述

PHP脚本发送代码(465端口)

require_once __DIR__ . "/vendor/autoload.php";

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;

...

$mail = new PHPMailer(true);

try {
    $mail->SMTPDebug = SMTP::DEBUG_CLIENT;                      // Enable verbose debug output
    $mail->isSMTP();                                            // Send using SMTP
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
    $mail->SMTPAuth = true;                                   // Enable SMTP authentication
    $mail->Host = 'smtp.exmail.qq.com';                         // Set the SMTP server to send through
    $mail->Port = 465;                                   // TCP port to connect to  , 465
    $mail->CharSet = "UTF-8";
    $mail->FromName = "lvpeilin";
    $mail->Username = 'lvpeilin@dyspace.net';                     // SMTP username
    $mail->Password = '******';                     // SMTP password, 授权码
    $mail->setFrom('lvpeilin@dyspace.net', '*****');
    $mail->addAddress('lvpeilin@dyspace.net', 'lvpeilin');     // Add a recipient
    $mail->isHTML(false);                                  // Set email format to HTML

    $mail->Subject = '一番赏';
    $mail->Body = '一番赏有新的已支付订单';
    $mail->send();
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

Yii框架发送代码(587端口)

1.配置 components

 'components' => [
 	...
 	 'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'useFileTransport' => false,  			// must have 
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.exmail.qq.com',  //每种邮箱的host配置不一样
                'username' => 'lvpeilin@dyspace.net',
                'password' => '*****************',
                'port' => '587',
                'encryption' => 'tls',
                'timeout' => 5,
                'StreamOptions' => ['tls' => ['allow_self_signed' => true, 'verify_peer' => false]],
            ],
            'messageConfig' => [
                'charset' => 'UTF-8',
            ],
        ],
 	...
 ]

2.发送代码

namespace app\common;

class MailUtils
{
    public static function mailDevelop($message = '我就试试!<br>', $mail_to = 'lvpeilin@dyspace.net')
    {
        $mail = \Yii::$app->mailer->compose();
        $mail->setFrom('lvpeilin@dyspace.net');
        $mail->setTo($mail_to);
        $mail->setSubject('一番开发bug提醒');
        $mail->setHtmlBody($message);
        try {
            $mail->send();
        }catch (\Exception $e){
            echo $e->getMessage();
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值