微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Swift Mailer ——Comprehensive mailing tools for PHP

Swift Mailer是一个PHP邮件发送类,直接与 SMTP 服务器通讯,具有非常高的发送速度和效率。

官网:http://swiftmailer.org/

Github:https://github.com/swiftmailer

使用说明:

require_once 'swiftmailer-master/lib/swift_required.PHP';//引入swiftmailer
				$email = '[email protected]';//接收邮箱
				//发送邮件,以QQ邮箱为例
				//配置邮件服务器,得到传输对象
				$transport=Swift_SmtpTransport::newInstance('smtp.qq.com',25);
				//设置登陆帐号和密码
				$transport->setUsername('[email protected]');//发送邮箱
				$transport->setPassword('******');
				//得到发送邮件对象Swift_Mailer对象
				$mailer=Swift_Mailer::newInstance($transport);
				//得到邮件信息对象
				$msg=Swift_Message::newInstance();
				//设置管理员的信息
				$msg->setFrom(array('[email protected]'=>'Meet Better Me'));
				//将邮件发给谁
				$msg->setTo($email);
				//设置邮件主题
				$msg->setSubject('网站有人留言啦!');
				$str = $message;
				$msg->setBody("留言内容为——{$str}",'text/html','utf-8');
				try{
					$mailer->send($msg);
				}catch(Swift_ConnectionException $e){
					echo $e.getMessage();
				}

效果

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐