Send mail using Pear's own mail class library

Source: Internet
Author: User
Use the Pear Mail class library to send mail, you can use the Pear Install command to mount the corresponding library
  1. $body = "dot i regenerate password";
  2. SENDMAIL_SMTP ("xxxxxxxx@qq.com", ' Test ', $body);
  3. function Sendmail_smtp ($smtpemailto, $mailsubject, $mailbody) {
  4. Error_reporting (7);
  5. Require_once ' mail.php ';
  6. Require_once ' mail/mime.php ';
  7. $from = ' admin@xxx.com ';
  8. $to = $smtpemailto;
  9. $password = ' xxxxxx ';
  10. $mail _config=array (
  11. "Host" = "smtp.ym.163.com",
  12. "Port" =>25,
  13. "Auth" =>true,
  14. "Username" = $from,
  15. "Password" = $password,
  16. "From" = $from,
  17. );
  18. $hdrs = Array (
  19. ' From ' = $from,
  20. ' To ' + $to,//mail address
  21. ' Subject ' = $mailsubject
  22. );
  23. $mime = new Mail_mime ();
  24. $mime->settxtbody ($text);
  25. Add an attachment
  26. $mime->addhtmlimage (' php.gif ', ' image/gif ', ' 12345 ', true);
  27. $mime->_build_params[' html_charset '] = "utf-8";//Set encoding format
  28. $mime->_build_params[' head_charset '] = "utf-8";//Set encoding format
  29. $mime->sethtmlbody ($mailbody);
  30. $body = $mime->get ();
  31. $hdrs = $mime->headers ($hdrs);
  32. $mail = mail::factory (' smtp ', $mail _config);
  33. $SUCC = $mail->send ($to, $hdrs, $body);
  34. if (Pear::iserror ($SUCC))
  35. {
  36. Echo ' Email sending failed: '. $SUCC->getmessage ();
  37. $err = ' Email sending failed: '. $SUCC->getmessage ();
  38. $content = $to. " \ t ". Date (' y-m-d h:i:s ')." \ t ". $err." \ r \ n ";
  39. }
  40. Else
  41. {
  42. $content = $to. " \ t ". Date (' y-m-d h:i:s ')." \ t Email sent succesfully \ r \ n ";
  43. return true;
  44. }
  45. }
Copy Code
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.