分享PHPMailer实现邮件发送的代码示例
分类:PHP_Python| 发布:llmaomi| 查看:168 | 发表时间:2015/4/9

发送邮件是常用的功能,LZ今天在项目中也碰到了,特此分享一下。
首先,去下载PHPMailer
1、https://github.com/dwqs/PHPMailer
2、http://download.csdn.net/detail/u011043843/8063583
下载之后,将文件解压到项目目录的对应位置,将class.phpmailer.php和class.smtp.php引入项目中,看代码:(解压的文件不要删除,否则不行)
03 | require ( "class.phpmailer.php" ); |
04 | require ( "class.smtp.php" ); |
05 | date_default_timezone_set( 'Asia/Shanghai' ); |
06 | $mail = new PHPMailer(); |
08 | $address = "camnpr@163.com" ; |
10 | $mail ->CharSet = "UTF-8" ; |
11 | $mail ->Host = "smtp.qq.com" ; |
12 | $mail ->SMTPAuth = true; |
13 | $mail ->Username = "1345995384@qq.com" ; |
14 | $mail ->Password = "**********" ; |
16 | $mail ->From = "461147874@qq.com" ; |
17 | $mail ->FromName = "dwqs" ; |
18 | $mail ->AddAddress( $address , "dwqs" ); |
24 | $mail ->Subject = "验证邮件" ; |
25 | $mail ->Body = "Hello,这是测试邮件" ; |
26 | $mail ->AltBody = "This is the body in plain text for non-HTML mail clients" ; |
29 | echo 'Mailer Error: ' . $mail ->ErrorInfo; |
31 | echo "Message sent!恭喜,邮件发送成功!" ; |
测试结果:

