本款邮件发送功能我们是用了国外一个开源码的邮件类,大家都可能用过的PHPMailer邮件类很简单,今天来讲一下简单的使用教程,有需要的朋友可以参考下,同时像其它的附件什么的,各位朋友可以给我意见.
要注意的内容:
1,邮件的字符集设置,$mail->CharSet = "GB2312"; 这里指定字符集!在这里我只指定为GB2312因为这样Outlook能正常显示邮件主题,我尝试过设为utf-8但在Outlook下显示乱码.
2,如果是发送html格式的邮件,那么记得也指定<meta ... charset=GB2312">
3,如果你想用它来群发邮件的话,记得修改包含文件函数,如:
require("phpmailer/class.phpmailer.php");
改为:require_once("phpmailer/class.phpmailer.php"); 否则的话会产生类的重定义.
PHPMailer邮件类代码如下:
- <?php
-
-
-
-
- require("phpmailer/class.phpmailer.php");
- function smtp_mail ( $sendto_email, $subject, $body, $extra_hdrs, $user_name) {
- $mail = new PHPMailer();
- $mail->IsSMTP();
- $mail->Host = "200.162.244.66";
- $mail->SMTPAuth = true;
- $mail->Username = "yourmail";
- $mail->Password = "mailPassword";
- $mail->From = "yourmail@cgsir.com";
- $mail->FromName = "cgsir.com管理员";
-
- $mail->CharSet = "GB2312";
- $mail->Encoding = "base64";
- $mail->AddAddress($sendto_email,"username");
- $mail->AddReplyTo("yourmail@cgsir.com","cgsir.com");
-
-
-
- $mail->IsHTML(true);
-
- $mail->Subject = $subject;
-
- $mail->Body = '
- <html><head>
- <meta http-equiv="Content-Language" content="zh-cn">
- <meta http-equiv="Content-Type" content="text/html; charset=GB2312">
- </head>
- <body>
- 欢迎来到<a href="http://www.phpfensi.com">http://www.phpfensi.com</a> <br /><br />
- 感谢您注册为本站会员!<br/><br/>
- </body>
- </html>
- ';
- $mail->AltBody ="text/html";
- if(!$mail->Send())
- {
- echo "邮件发送有误 <p>";
- echo "邮件错误信息: " . $mail->ErrorInfo;
- exit;
- }
- else {
- echo "$user_name 邮件发送成功!<br />";
- }
- }
-
- smtp_mail('yourmail@phpfensi.com', '欢迎来到phpfensi.com!', 'NULL', 'cgsir.com', 'username');
- ?>
|