76 lines
3.2 KiB
PHP
76 lines
3.2 KiB
PHP
<?php
|
||
/**
|
||
* @copyright Copyright (c) 2023 李志强
|
||
* @author 李志强
|
||
* @link https://www.yunzer.cn
|
||
*/
|
||
declare(strict_types=1);
|
||
|
||
namespace app\command;
|
||
|
||
use think\console\Command;
|
||
use think\console\Input;
|
||
use think\console\input\Argument;
|
||
use think\console\input\Option;
|
||
use think\console\Output;
|
||
use PHPMailer\PHPMailer\PHPMailer;
|
||
use PHPMailer\PHPMailer\SMTP;
|
||
use PHPMailer\PHPMailer\Exception;
|
||
|
||
class Test extends Command
|
||
{
|
||
protected function configure()
|
||
{
|
||
// 指令配置
|
||
$this->setName('test')
|
||
->setDescription('the test command');
|
||
}
|
||
|
||
protected function execute(Input $input, Output $output)
|
||
{
|
||
Queue::push(Job1::class, $data = '', $queue = null);
|
||
exit;
|
||
|
||
$mail = new PHPMailer(true);
|
||
|
||
try {
|
||
//邮件服务器配置
|
||
$mail->CharSet = "UTF-8"; //设定邮件编码
|
||
$mail->SMTPDebug = SMTP::DEBUG_SERVER; // DEBUG模式,开发阶段建议开启,生产阶段注释掉
|
||
$mail->isSMTP(); // 使用SMTP服务
|
||
$mail->Host = 'smtp.qq.com'; // 发送方的SMTP服务器地址
|
||
$mail->SMTPAuth = true; // 是否使用身份验证
|
||
$mail->Username = '357099073@qq.com'; // 发送方的163邮箱用户名,就是你申请163的SMTP服务使用的163邮箱
|
||
$mail->Password = 'iectyrppelsxbhge'; //发送方的邮箱密码,注意用163邮箱这里填写的是“客户端授权密码”而不是邮箱的登录密码!
|
||
$mail->SMTPSecure = "ssl"; // 使用ssl协议方式
|
||
$mail->Port = 465; // 163邮箱的ssl协议方式端口号是465/994
|
||
|
||
//Recipients
|
||
$mail->setFrom('357099073@qq.com', '美天科技'); //设置发件人信息,如邮件格式说明中的发件人,这里会显示为Mailer(xxxx@163.com),Mailer是当做名字显示
|
||
$mail->addAddress('357099073@qq.com', 'Joe User'); //设置收件人信息,如邮件格式说明中的收件人,这里会显示为Liang(yyyy@163.com)
|
||
// $mail->addAddress('ellen@example.com'); //Name is optional
|
||
// $mail->addReplyTo('info@example.com', 'Information');
|
||
// $mail->addCC('cc@example.com');
|
||
// $mail->addBCC('bcc@example.com');
|
||
|
||
//Attachments
|
||
// $mail->addAttachment('/var/tmp/file.tar.gz'); //添加附件
|
||
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //添加图片
|
||
|
||
//Content
|
||
$mail->isHTML(true); // 是否以HTML文档格式发送 发送后客户端可直接显示对应HTML内容
|
||
$mail->Subject = '这是一个测试邮件!'; //邮件标题
|
||
$mail->Body = '邮件内容是 <b>您的验证码是:123456</b>,哈哈哈!'; // 邮件正文
|
||
// $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
|
||
|
||
if (!$mail->send()) { // 发送邮件
|
||
echo "邮件未发送成功!";
|
||
echo "Mailer Error: " . $mail->ErrorInfo; // 输出错误信息
|
||
} else {
|
||
echo '邮件发送成功!';
|
||
}
|
||
} catch (Exception $e) {
|
||
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
|
||
}
|
||
}
|
||
} |