zoukankan      html  css  js  c++  java
  • PHP使用SwiftMailer发送邮件

    用到了swiftmailer 的lib库

    官方网址:http://swiftmailer.org/

    require_once 'lib/swift_required.php';
    //给我发送邮件
    function mailer(){
        $body ="要发送的内容";
        $subject = "要发送主题"

        $transport = Swift_SmtpTransport::newInstance('smtp.qq.com', 25);//设置发送 smtp 服务器和端口
        $transport->setUsername('发送邮箱 地址 ');
        $transport->setPassword('发送邮箱密码');
        $mailer = Swift_Mailer::newInstance($transport);
        $message = Swift_Message::newInstance();
        $message->setFrom(array( '发送邮箱地址'  =>'发送人'));
        $message->setTo(array('接受邮箱地址' => '接受人'));
        $message->setSubject($subject);
        $message->setBody($body, 'text/html', 'utf-8');
        //$message->attach(Swift_Attachment::fromPath('pic.jpg', 'image/jpeg')->setFilename('rename_pic.jpg'));//发送附件
        try{
            $mailer->send($message);
        }
        catch (Swift_ConnectionException $e){
            echo 'There was a problem communicating with SMTP: ' . $e->getMessage();
        }
    }

    Swift 直接与 SMTP 服务器通讯,具有非常高的发送速度和效率。

    Swiftmailer的特点:

    1. Send emails using SMTP, sendmail, postfix or a custom Transport implementation of your own
    2. Support servers that require username & password and/or encryption
    3. Protect from header injection attacks without stripping request data content
    4. Send MIME compliant HTML/multipart emails
    5. Use event-driven plugins to customize the library
    6. Handle large attachments and inline/embedded images with low memory use

  • 相关阅读:
    寒假特训——搜索——H
    寒假特训——I
    寒假训练——搜索 K
    three.js 加载STL文件
    three.js 加载3DS 404 文件找不到
    C# 请求数据 方式1
    学习 一个简单的业务处理
    ABP 05 创建Model 以及 相应的增删改查
    ABP 04 用户的创建
    ABP 00 常用知识
  • 原文地址:https://www.cnblogs.com/VellBibi/p/3339721.html
Copyright © 2011-2022 走看看