easy-swoole / smtp

10 stars 7 forks source link

qq邮箱发到qq邮箱,发送中文名称的附件,附件名称变成乱码。 #16

Open XueSiLf opened 3 years ago

XueSiLf commented 3 years ago

复现代码:

<?php
/**
 * Created by PhpStorm.
 * User: XueSi
 * Email: <1592328848@qq.com>
 * Date: 2021/4/22
 * Time: 23:53
 */

use EasySwoole\Smtp\Mailer;
use EasySwoole\Smtp\MailerConfig;
use EasySwoole\Smtp\Message\Html;
use EasySwoole\Smtp\Message\Attach;

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

// 必须用go
go(function () {
    $config = new MailerConfig();
    $config->setServer('smtp.qq.com');
    $config->setPort(465);
    $config->setSsl(false);
    $config->setMailFrom('EasySwooleTest');
    $config->setUsername('1592328848@qq.com');
    $config->setPassword('xxxx');
    $config->setTimeout(10);//设置客户端连接超时时间
    $config->setMaxPackage(1024 * 1024 * 5);//设置包发送的大小:5M

    // 设置文本或者html格式
    $mimeBean = new Html();
    $mimeBean->setSubject('XueSi真帅 XueSi真帅 XueSi真帅 XueSi真帅 XueSi真帅!');
    $mimeBean->setBody('<h1> XueSi真帅 XueSi真帅 XueSi真帅 XueSi真帅 XueSi真帅</h1>');

    // 添加附件
    $mimeBean->addAttachment(Attach::create(__DIR__ . '/我是测试.txt'));

    $mailer = new Mailer($config);
    $mailer->sendTo('1592328848@qq.com', $mimeBean);
});
XueSiLf commented 3 years ago

image