php发邮件:swiftmailer, php邮件库——swiftmailer
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php发邮件:swiftmailer, php邮件库——swiftmailer,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2386字,纯文字阅读大概需要4分钟。
内容图文
php发邮件:swiftmailer, php邮件库——swiftmailer
最近看到一个好的php邮件库,与phpmailer作用一样,但性能比phpmailer好,尤其是在处理附件的能力上,发送邮件成功的几率也高。
github地址:https://github.com/swiftmailer/swiftmailer.git
require_once ("lib/swift_required.php"); // 创建Transport对象,设置邮件服务器和端口号,并设置用户名和密码以供验证 $transport = Swift_SmtpTransport::newInstance(‘smtp.163.com‘, 25) ->setUsername(‘username@163.com‘) ->setPassword(‘password‘); // 创建mailer对象 $mailer = Swift_Mailer::newInstance($transport); // 创建message对象 $message = Swift_Message::newInstance(); // 设置邮件主题 $message->setSubject(‘这是一份测试邮件‘) // 设置邮件内容,可以省略content-type ->setBody( ‘<html>‘ . ‘ <head></head>‘ . ‘ <body>‘ . ‘ Here is an image <img src="‘ . // 内嵌文件 $message->embed(Swift_Image::fromPath(‘image.jpg‘)) . ‘" alt="Image" />‘ . ‘ Rest of message‘ . ‘<a href="http://www.baidu.com">百度</a>‘. ‘ </body>‘ . ‘</html>‘, ‘text/html‘ ); // 创建attachment对象,content-type这个参数可以省略 $attachment = Swift_Attachment::fromPath(‘image.jpg‘, ‘image/jpeg‘) ->setFilename(‘cool.jpg‘); // 添加附件 $message->attach($attachment); // 用关联数组设置收件人地址,可以设置多个收件人 $message->setTo(array(‘to@qq.com‘ => ‘toName‘)); // 用关联数组设置发件人地址,可以设置多个发件人 $message->setFrom(array( ‘from@163.com‘ => ‘fromName‘, )); // 添加抄送人 $message->setCc(array( ‘Cc@qq.com‘ => ‘Cc‘ )); // 添加密送人 $message->setBcc(array( ‘Bcc@qq.com‘ => ‘Bcc‘ )); // 设置邮件回执 $message->setReadReceiptTo(‘receipt@163.com‘); // 发送邮件 $result = $mailer->send($message);
测试代码,测试例子:
$Requests = __DIR__ . ‘/../../../vendor/swiftmailer/swiftmailer/lib/swift_required.php‘; require_once ($Requests); //Requests::register_autoloader (); // 创建Transport对象,设置邮件服务器和端口号,并设置用户名和密码以供验证 $transport = \Swift_SmtpTransport::newInstance(‘smtp.exmail.qq.com‘, 25) ->setUsername(‘business@VariFlight.com‘) ->setPassword(‘Youxikaishi04‘); // 创建mailer对象 $mailer = \Swift_Mailer::newInstance($transport); // 创建message对象 $message = \Swift_Message::newInstance(); // 设置邮件主题 $message->setSubject(‘这是一份测试邮件‘)->setBody(‘aaaa‘); // 用关联数组设置收件人地址,可以设置多个收件人 $message->setTo(array(‘muyang@variflight.com‘ => ‘muyang‘)); // 用关联数组设置发件人地址,可以设置多个发件人 $message->setFrom(array( ‘business@VariFlight.com‘ => ‘shandongair‘, )); // 发送邮件 $result = $mailer->send($message); echo "aaa"; exit;
原文:http://www.cnblogs.com/achengmu/p/7677799.html
内容总结
以上是互联网集市为您收集整理的php发邮件:swiftmailer, php邮件库——swiftmailer全部内容,希望文章能够帮你解决php发邮件:swiftmailer, php邮件库——swiftmailer所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。