当前位置: 首页 > 工具软件 > PHPMailer > 使用案例 >

Laravel5 +phpmailer

周弘毅
2023-12-01
public  function  index()
    {
//        echo phpinfo();die();
        $mail = new \PHPMailer(true); // notice the \  you have to use root namespace here
        try {
            $mail->isSMTP(); // tell to use smtp

            $mail->CharSet = "utf-8"; // set charset to utf8
            $mail->SMTPAuth = true;  // use smpt auth
            $mail->SMTPSecure = "tls"; // or ssl
            $mail->Host = "smtp.qq.com";

            $mail->Port = 25; // most likely something different for you. This is the mailtrap.io port i use for testing.
            $mail->Username = "xxxxx@qq.com";
            $mail->Password = "XXXXX";//去开通的qq或163邮箱中找,这里用的不是邮箱的密码,而是开通之后的一个token
            $mail->setFrom("XXXXXX@qq.com", "siwei");//设置邮件来源
            $mail->Subject = "Test";
            $mail->MsgHTML("Thisisatest");
//            $mail->addAddress("xxxxxxx@qq.com", "leon");
            $mail->addAddress("xxxxx_1@163.com", "leon");
            $mail->send();
        } catch (phpmailerException $e) {
            dd($e);
        } catch (Exception $e) {
            dd($e);
        }
        die('success');
    }


安装方法 :
composer require phpmailer/phpmailer

如何开启参见下面的url

PHPMailer配置QQ邮箱163邮箱和谷歌邮箱发送邮件

 类似资料: