在Thinkphp6发邮件

$transport = \Swift_SmtpTransport::newInstance('smtp.163.com', 25)
                  ->setUsername('[email protected]')
                  ->setPassword('7654321a')
                  ;
                // 创建账号
                $mailer = \Swift_Mailer::newInstance($transport);
                // 创建邮件内容
                $message = \Swift_Message::newInstance('验证码')
                  ->setFrom(array('[email protected]' => '四个人'))
                  ->setTo(array(‘[email protected]’))
                  ->setBody('你的验证码是:1234')
                  ;
                // 发送邮件
                $result = $mailer->send($message);

如果成功的话,返回1.

记住一定要在thinkphp6里面安装 swiftmailer组件。

发布了66 篇原创文章 · 获赞 27 · 访问量 12万+

猜你喜欢

转载自blog.csdn.net/u010261924/article/details/104747822