laravel中使用swiftmailer发送email

laravel

 

配置.env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.qq.com
MAIL_PORT=587
MAIL_USERNAME=2323178881@qq.com
MAIL_PASSWORD=njdlyvbchdwhdghj //qq邮箱开启smtp分配的随机字符串,不是邮箱密码
MAIL_ENCRYPTION=tls

控制器代码:
// Create the Transport
$transport = (new \Swift_SmtpTransport(env("MAIL_HOST"), env("MAIL_PORT")))->setUsername(env("MAIL_USERNAME"))->setPassword(env("MAIL_PASSWORD"));
// Create the Mailer using your created Transport
$mailer = new \Swift_Mailer($transport);

// Create a message
$message = (new \Swift_Message("hello world"))
    ->setFrom([env("MAIL_USERNAME")])
    ->setTo(['15164392341@163.com', '15164392341@163.com' => 'datou'])
    ->setBody("hello world");

// Send the message
$result = $mailer->send($message);
如果发现下载不了或者地址失效,请联系客服QQ: 2323178881
找资料 » laravel中使用swiftmailer发送email

提供最优质的资源集合

立即查看 了解详情