| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 | <?phpnamespace app\common\util;use PHPMailer\PHPMailer\Exception;use PHPMailer\PHPMailer\PHPMailer;/** * 动态邮箱类 */class Email{    public function sendEmail($toEmail, $tp): int    {        $mail = new PHPMailer();        $mail->isSMTP();// 使用SMTP服务        $mail->CharSet = "utf8";// 编码格式为utf8,不设置编码的话,中文会出现乱码        $mail->Host = "smtp.qq.com";// 发送方的SMTP服务器地址        $mail->SMTPAuth = true;// 是否使用身份验证        $mail->Username = "845178954@qq.com";// 发送方的qq邮箱用户名,就是你申请qq的SMTP服务使用的qq邮箱        $mail->Password = "dptntlmpifkqbfgb";// 发送方的邮箱密码,注意用163邮箱这里填写的是“客户端授权密码”而不是邮箱的登录密码!        $mail->SMTPSecure = "ssl";// 使用ssl协议方式        $mail->Port = 465;// 163邮箱的ssl协议方式端口号是465/994        try {            $mail->setFrom("845178954@qq.com", "皮编程");        } catch (Exception $e) {        }// 设置发件人信息,如邮件格式说明中的发件人,这里会显示为Mailer(xxxx@163.com),Mailer是当做名字显示        try {            $mail->addAddress($toEmail, '教务');        } catch (Exception $e) {        }// 设置收件人信息,如邮件格式说明中的收件人,这里会显示为Liang(yyyy@163.com)        try {            $mail->addReplyTo("845178954@qq.com", "皮编程");        } catch (Exception $e) {        }// 设置回复人信息,指的是收件人收到邮件后,如果要回复,回复邮件将发送到的邮箱地址        //$mail->addCC("xxx@163.com");// 设置邮件抄送人,可以只写地址,上述的设置也可以只写地址(这个人也能收到邮件)        //$mail->addBCC("xxx@163.com");// 设置秘密抄送人(这个人也能收到邮件)        //$mail->addAttachment("bug0.jpg");// 添加附件        $mail->isHTML();        $mail->Subject = "【商品发货通知】";// 邮件标题        try {            $mail->MsgHTML($tp);        } catch (Exception $e) {        }// 邮件正文        //$mail->AltBody = "This is the plain text纯文本";// 这个是设置纯文本方式显示的正文内容,如果不支持Html方式,就会用到这个,基本无用        if (!$mail->send()) {// 发送邮件            // return $this->api("Mailer Error: ".$mail->ErrorInfo, '发送失败~', 400);            return 400;        } else {            return 200;        }    }    public function getTp($phone, $goodsname, $goodstype, $num, $price, $total_amount, $status_text, $password = ''): string    {        return '<!DOCTYPE html><html lang=""><head>  <title></title>  <meta charset="utf-8">  <meta name="viewport" content="width=device-width, initial-scale=1">  <style>      table{        border: 1px solid red;      }  </style></head><body><div class="container mt-3">  <h2>订单信息: </h2>    <h5>账号: ' . $phone . '</h5>         <h5>商品: ' . $goodsname . '</h5>       <h5>类型: ' . $goodstype . '</h5>          <h5>数量: ' . $num . '</h5>         <h5>单价: ' . $price . '</h5>         <h5>总金额: ' . $total_amount . '</h5>         <h5>状态: ' . $status_text . '</h5>      <h5>卡密: ' . $password . '</h5>        </div></body></html>';    }}
 |