mail.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. *
  4. * @author: peng.shan <peng.shan@happyelements.com>
  5. * @version $Id: mail.php 156323 2011-11-28 02:57:21Z peng.shan $
  6. */
  7. class Mail {
  8. function send_mail($to,$subject = "",$body = "") {
  9. //error_reporting(E_STRICT);
  10. date_default_timezone_set("Asia/Shanghai");//设定时区东八区
  11. require_once('../libs/phpmailer/class.phpmailer.php');
  12. include("../libs/phpmailer/class.pop3.php");
  13. $mail = new PHPMailer(); //new一个PHPMailer对象出来
  14. $body = str_replace("[\]",'',$body); //对邮件内容进行必要的过滤
  15. $mail->CharSet ="UTF-8";//设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码
  16. // $mail->IsSMTP(); // 设定使用SMTP服务
  17. // $mail->SMTPDebug = 1; // 启用SMTP调试功能
  18. // 1 = errors and messages
  19. // 2 = messages only
  20. $mail->SMTPAuth = true; // 启用 SMTP 验证功能
  21. $mail->SMTPSecure = "ssl"; // 安全协议
  22. $mail->Host = "MAILBOX03.internal.baidu.com"; // SMTP 服务器
  23. $mail->Port = 465; // SMTP服务器的端口号
  24. $mail->Username = "zhuwemxuan"; // SMTP服务器用户名
  25. $mail->Password = "xxxxx"; // SMTP服务器密码
  26. $mail->SetFrom('xxxx@baidu.com', '朱文轩');
  27. $mail->AddReplyTo("xxxx@baidu.com","邮件回复人的名称");
  28. $mail->Subject = $subject;
  29. $mail->AltBody = "To view the message, please use an HTML compatible email viewer! - From www.jiucool.com"; // optional, comment out and test
  30. $mail->MsgHTML($body);
  31. $address = $to;
  32. $mail->AddAddress($address, "收件人名称");
  33. if(!$mail->Send()) {
  34. echo "Mailer Error: " . $mail->ErrorInfo;
  35. } else {
  36. echo "Message sent!恭喜,邮件发送成功!";
  37. }
  38. }
  39. function new_send_mail(){
  40. mail("xxxx@baidu.com","asdfasdf","asdfasdf");
  41. // require_once('../libs/phpmailer/class.phpmailer.php');
  42. // $mail = new PHPMailer();
  43. // $body = "asdfdsf";
  44. // $body = str_replace("[\]",'',$body);
  45. // $mail->SMTPAuth = true; // 启用 SMTP 验证功能
  46. // $mail->SMTPSecure = "ssl"; // 安全协议
  47. // $mail->IsSMTP();
  48. // $mail->CharSet='UTF-8';
  49. // $mail->SMTPDebug = 2;
  50. // $mail->Host = 'smtp.baidu.com';
  51. // $mail->Port = 25;
  52. // $mail->Username = "xxxx@baidu.com";
  53. // $mail->Password = "xxxx";
  54. // $mail->SetFrom('xxxx@baidu.com', 'First Last');
  55. //
  56. // $mail->AddReplyTo("zhuwen_xuan@126.com","First Last");
  57. //
  58. // $mail->Subject = "PHPMailer Test Subject via POP before SMTP, basic";
  59. //
  60. // $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
  61. //
  62. // $mail->MsgHTML($body);
  63. //
  64. // $address = "zhuwen_xuan@126.com";
  65. // $mail->AddAddress($address, "John Doe");
  66. // if(!$mail->Send()) {
  67. // echo "Mailer Error: " . $mail->ErrorInfo;
  68. // } else {
  69. // echo "Message sent!";
  70. // }
  71. }
  72. function sendMain126(){
  73. require_once('../libs/phpmailer/class.phpmailer.php');
  74. $mail = new PHPMailer();
  75. $body = "asdfdsf";
  76. $body = str_replace("[\]",'',$body);
  77. $mail->SMTPAuth = true; // 启用 SMTP 验证功能
  78. $mail->SMTPSecure = "ssl"; // 安全协议
  79. $mail->IsSMTP();
  80. $mail->CharSet='UTF-8';
  81. $mail->SMTPDebug = 2;
  82. $mail->Host = 'smtp.126.com';
  83. $mail->Port = 465;
  84. $mail->Username = "zhuwen_xuan@126.com";
  85. $mail->Password = "zwx19840818";
  86. $mail->SetFrom('zhuwen_xuan@126.com', 'First Last');
  87. $mail->AddReplyTo("xxxx@baidu.com","First Last");
  88. $mail->Subject = "PHPMailer Test Subject via POP before SMTP, basic";
  89. $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
  90. $mail->MsgHTML($body);
  91. $address = "xxxxxx@baidu.com";
  92. $mail->AddAddress($address, "John Doe");
  93. if(!$mail->Send()) {
  94. echo "Mailer Error: " . $mail->ErrorInfo;
  95. } else {
  96. echo "Message sent!";
  97. }
  98. }
  99. }
  100. $m = new Mail();
  101. $m->new_send_mail();