当前位置:Gxlcms > PHP教程 > PHPmailer发送邮件及乱码问题的解决

PHPmailer发送邮件及乱码问题的解决

时间:2021-07-01 10:21:17 帮助过:29人阅读

  1. phpmailer邮件发送测试-bbs.it-home.org

  2. 请你输入收信的邮箱地址:

2、发邮件程序 send.php

  1. /**

  2. * PHPMailer邮件发送
  3. * Edit bbs.it-home.org
  4. */
  5. require("class.phpmailer.php");
  6. $mail = new PHPMailer();
  7. $mail->CharSet = "gb2312"; // 这里指定字符集!如果是utf-8则将gb2312修改为utf-8
  8. $mail->Encoding = "base64";
  9. $address = $_POST['address'];
  10. $mail->IsSMTP(); // set mailer to use SMTP
  11. $mail->Host = "smtp.126.com"; // specify main and backup server
  12. $mail->SMTPAuth = true; // turn on SMTP authentication
  13. $mail->Username = ""; // SMTP username
  14. $mail->Password = "******"; // SMTP password

  15. $mail->From = "";

  16. $mail->FromName = "rokaye";
  17. $mail->AddAddress("$address", "");
  18. //$mail->AddAddress(""); // name is optional
  19. //$mail->AddReplyTo("", "");

  20. //$mail->WordWrap = 50; // set word wrap to 50 characters

  21. //$mail->AddAttachment("/var/tmp/file.tar.gz"); // add attachments
  22. //$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional name
  23. //$mail->IsHTML(true); // set email format to HTML

  24. $mail->Subject = "PHPMailer测试邮件";

  25. $mail->Body = "Hello,这是rokaye的测试邮件";
  26. $mail->AltBody = "This is the body in plain text for non-HTML mail clients";

  27. if(!$mail->Send())

  28. {
  29. echo "Message could not be sent.

    ";

  30. echo "Mailer Error: " . $mail->ErrorInfo;
  31. exit;
  32. }

  33. echo "Message has been sent";

  34. ?>

有关乱码的问题,多是因为没有指定所要求的编码而引起的。

  1. $mail->CharSet = "gb2312"; // 指定字符集!如果是utf-8则将gb2312修改为utf-8
  2. $mail->Encoding = "base64";

这样操作后,就不会出现乱码了。

人气教程排行