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

Swift Mailer 和前面介绍的PHPMailer一样,也是一个PHP邮件发送类。它不依赖于 PHP 自带的mail() 函数,因为该函数在发送多个邮件时占用的系统资源很高。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

由于自己还没有用过,所以说以后自己使用以后再做补充。

官方网址: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();
 }
}
?>
文章标签:

引用地址:http://www.biaodianfu.com/swiftmailer.html

该日志还没有评论。

发表评论




想让您的头像与众不同,请注册Gravatar