Swift Mailer:又一个强大的PHP邮件类

作者Veris 文章分类 分类:PHP 文章评论 0条评论 阅读次数 已被围观 2903

Swift Mailer 和前面介绍的PHPMailer一样,也是一个PHP邮件发送类。它不依赖于 PHP 自带的mail() 函数,因为该函数在发送多个邮件时占用的系统资源很高。Swift 直接与 SMTP 服务器通讯,具有非常高的发送速度和效率。
Swiftmailer的特点:
Send emails using SMTP, sendmail, postfix or a custom Transport implementation of your own
Support servers that require username & password and/or encryption
Protect from header injection attacks without stripping request data content
Send MIME compliant HTML/multipart emails
Use event-driven plugins to customize the library
Handle large attachments and inline/embedded images with low memory use
由于自己还没有用过,所以说以后自己使用以后再做补充。
官方网址:http://swiftmailer.org/
Swiftmailer的使用方法:

<?php
    require_once 'lib/swift_required.php';
    function sendMail() {
        $transport = Swift_SmtpTransport::newInstance('smtp.163.com', 25);
        $transport - > setUsername('username@163.com');
        $transport - > setPassword('password');
        $mailer = Swift_Mailer::newInstance($transport);
        $message = Swift_Message::newInstance();
        $message - > setFrom(array('username@163.com' = > 'name'));
        $message - > setTo(array('whoever@163.com' = > 'Mr.Right', 'whoever@qq.com' = > 'Mr.Wrong'));
        $message - > setSubject("This is a subject");
        $message - > setBody('Here is the message', '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 Mailer:又一个强大的PHP邮件类》

发表评论: